plot
Plot driving scenario
Description
plot(
creates a 3-D plot with
orthonormal perspective, as seen from immediately above the driving scenario,
scenario
)scenario
.
plot(
specifies options using one or more name-value pairs. For example, you can use these
options to display road centers and actor waypoints on the plot.scenario
,Name,Value
)
Examples
Create and Display Road Boundaries
Create a driving scenario containing a figure-8 road specified in the world coordinates of the scenario. Convert the world coordinates of the scenario to the coordinate system of the ego vehicle.
Create an empty driving scenario.
scenario = drivingScenario;
Add a figure-8 road to the scenario. Display the scenario.
roadCenters = [0 0 1 20 -20 1 20 20 1 -20 -20 1 -20 20 1 0 0 1]; roadWidth = 3; bankAngle = [0 15 15 -15 -15 0]; road(scenario,roadCenters,roadWidth,bankAngle); plot(scenario)
Add an ego vehicle to the scenario. Position the vehicle at world coordinates (20, –20) and orient it at a –15 degree yaw angle.
ego = actor(scenario,'ClassID',1,'Position',[20 -20 0],'Yaw',-15);
Obtain the road boundaries in ego vehicle coordinates by using the roadBoundaries
function. Specify the ego vehicle as the input argument.
rbEgo1 = roadBoundaries(ego);
Display the result on a bird's-eye plot.
bep = birdsEyePlot; lbp = laneBoundaryPlotter(bep,'DisplayName','Road'); plotLaneBoundary(lbp,rbEgo1)
Obtain the road boundaries in world coordinates by using the roadBoundaries
function. Specify the scenario as the input argument.
rbScenario = roadBoundaries(scenario);
Obtain the road boundaries in ego vehicle coordinates by using the driving.scenario.roadBoundariesToEgo
function.
rbEgo2 = driving.scenario.roadBoundariesToEgo(rbScenario,ego);
Display the road boundaries on a bird's-eye plot.
bep = birdsEyePlot; lbp = laneBoundaryPlotter(bep,'DisplayName','Road boundaries'); plotLaneBoundary(lbp,{rbEgo2})
Create Driving Scenario with Multiple Actors and Roads
Create a driving scenario containing a curved road, two straight roads, and two actors: a car and a bicycle. Both actors move along the road for 60 seconds.
Create the driving scenario object.
scenario = drivingScenario('SampleTime',0.1','StopTime',60);
Create the curved road using road center points following the arc of a circle with an 800-meter radius. The arc starts at 0°, ends at 90°, and is sampled at 5° increments.
angs = [0:5:90]'; R = 800; roadcenters = R*[cosd(angs) sind(angs) zeros(size(angs))]; roadwidth = 10; cr = road(scenario,roadcenters,roadwidth);
Add two straight roads with the default width, using road center points at each end. To the first straight road add barriers on both road edges.
roadcenters = [700 0 0; 100 0 0]; sr1 = road(scenario,roadcenters); barrier(scenario,sr1) barrier(scenario,sr1,'RoadEdge','left') roadcenters = [400 400 0; 0 0 0]; road(scenario,roadcenters);
Get the road boundaries.
rbdry = roadBoundaries(scenario);
Add a car and a bicycle to the scenario. Position the car at the beginning of the first straight road.
car = vehicle(scenario,'ClassID',1,'Position',[700 0 0], ... 'Length',3,'Width',2,'Height',1.6);
Position the bicycle farther down the road.
bicycle = actor(scenario,'ClassID',3,'Position',[706 376 0]', ... 'Length',2,'Width',0.45,'Height',1.5);
Plot the scenario.
plot(scenario,'Centerline','on','RoadCenters','on'); title('Scenario');
Display the actor poses and profiles.
allActorPoses = actorPoses(scenario)
allActorPoses=242×1 struct array with fields:
ActorID
Position
Velocity
Roll
Pitch
Yaw
AngularVelocity
allActorProfiles = actorProfiles(scenario)
allActorProfiles=242×1 struct array with fields:
ActorID
ClassID
Length
Width
Height
OriginOffset
MeshVertices
MeshFaces
RCSPattern
RCSAzimuthAngles
RCSElevationAngles
Because there are barriers in this scenario, and each barrier segment is considered an actor, actorPoses
and actorProfiles
functions return the poses of all stationary and non-stationary actors. To only obtain the poses and profiles of non-stationary actors such as vehicles and bicycles, first obtain their corresponding actor IDs using the scenario.Actors.ActorID
property.
movableActorIDs = [scenario.Actors.ActorID];
Then, use those IDs to filter only non-stationary actor poses and profiles.
movableActorPoseIndices = ismember([allActorPoses.ActorID],movableActorIDs); movableActorPoses = allActorPoses(movableActorPoseIndices)
movableActorPoses=2×1 struct array with fields:
ActorID
Position
Velocity
Roll
Pitch
Yaw
AngularVelocity
movableActorProfiles = allActorProfiles(movableActorPoseIndices)
movableActorProfiles=2×1 struct array with fields:
ActorID
ClassID
Length
Width
Height
OriginOffset
MeshVertices
MeshFaces
RCSPattern
RCSAzimuthAngles
RCSElevationAngles
Create Trajectory with Front-Axle Steering for Long Vehicle
Since R2024b
Create a driving scenario object.
scenario = drivingScenario;
Add road and lane segments to the driving scenario.
roadCenters = [0.5 15.84 0; 35.5 5.85 0; 28.6 1.35 0; 22.8 -18.64 0]; marking = [laneMarking("Solid",Color=[0.98 0.86 0.36]) ... laneMarking("Dashed") ... laneMarking("Dashed")]; laneSpecification = lanespec(2,Width=5,Marking=marking); road(scenario,roadCenters,Lanes=laneSpecification,Name="Road")
ans = Road with properties: Name: "Road" RoadID: 1 RoadCenters: [4×3 double] RoadWidth: 10.1500 BankAngle: [4×1 double] Heading: [4×1 double]
Specify the vehicle parameters, along with its waypoints and relative speed values.
egoVehicle = vehicle(scenario, ... ClassID=2, ... Length=12, ... Width=2.5, ... Height=3.5, ... Position=[12.01 21.84 0.01], ... RearOverhang=1, ... FrontOverhang=0.9, ... Mesh=driving.scenario.truckMesh, ... Name="Truck"); waypoints = [11.91 23.84 0.01; 19.7 25.94 0.01; 31.8 24.34 0.01; 40.29 15.55 0.01; 38.59 5.15 0.01; 31 0.05 0.01; 26.4 -4.75 0.01; 25.3 -12.04 0.01]; speed = [30 30 30 30 30 30 30 30]';
Create a trajectory for the vehicle, with reference to the front-axle for steering.
trajectory(egoVehicle,waypoints,speed,ReferenceSteerPosition="front-axle")
Plot the scenario, displaying the rear-axle trajectory, and run the simulation. Observe the dashed line trajectory for the rear axle, created with reference to the front-axle steering.
plot(scenario,Waypoints="on",RoadCenters="on",ShowRearAxle="on") title("Trajectory with Front-Axle Steering") while advance(scenario) pause(0.1) end
Input Arguments
scenario
— Driving scenario
drivingScenario
object
Driving scenario, specified as a drivingScenario
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: plot(sc,'Centerline','on','RoadCenters','on')
displays
the center line and road centers of each road segment.
Parent
— Axes in which to draw plot
Axes
object
Axes in which to draw the plot, specified as the comma-separated pair consisting of
'Parent'
and an Axes
object. If you do not
specify Parent
, a new figure is created.
Centerline
— Display center line of roads
'off'
(default) | 'on'
Display the center line of roads, specified as the comma-separated pair consisting of
'Centerline'
and 'off'
or
'on'
. The center line follows the middle of each road
segment. Center lines are discontinuous through areas such as intersections or road
splits.
RoadCenters
— Display road centers
'off'
(default) | 'on'
Display road centers, specified as the comma-separated pair consisting of
'RoadCenters'
and 'off'
or
'on'
. The road centers define the roads shown in the
plot.
Waypoints
— Display actor waypoints
'off'
(default) | 'on'
Display actor waypoints, specified as the comma-separated pair consisting of
'Waypoints'
and 'off'
or
'on'
. Waypoints define the trajectory of the actor.
Meshes
— Display actor meshes
'off'
(default) | 'on'
Display actor meshes instead of cuboids, specified as the comma-separated pair
consisting of 'Meshes'
and 'off'
or
'on'
.
ActorIndicators
— Actors around which to draw indicator
[]
(default) | vector of ActorID
integers
Actors around which to draw indicators, specified as the
comma-separated pair consisting of 'ActorIndicators'
and a vector of ActorID
integers. The driving
scenario plot draws circles around the actors that have the specified
ActorID
values. Each circle is the same color as
the actor that it surrounds. The circles are not sensor coverage
areas.
Use this name-value pair to highlight the ego vehicle in driving scenarios that contain several vehicles.
ParkingLotEdges
— Display parking lot edge numbers
'off'
(default) | 'on'
Display parking lot edge numbers, specified as the comma-separated
pair consisting of 'ParkingLotEdges'
and
'off'
or 'on'
. The order of
the edge numbers is based on the order of the vertices defined in each
parking lot.
ShowRearAxle
— Display rear-axle trajectory
"off"
(default) | "on"
Since R2024b
Display rear-axle trajectory, specified as "off"
or
"on"
.
If you set ShowRearAxle
to
"on"
, the plot
function
displays both the front-axle and rear-axle trajectories. The front-axle
trajectories are solid lines crossing each waypoint, whereas, the
rear-axle trajectories are dashed lines in which arrows represent the
heading direction of the vehicle at each waypoint. For more information,
see the Create Trajectory with Front-Axle Steering for Long Vehicle example.
Note
To use the ShowRearAxle
name-value
argument, your driving scenario must contain the trajectory of a
vehicle with front-axle steering.
Tips
To rotate any plot, in the figure window, select View > Camera Toolbar.
Version History
Introduced in R2017aR2024b: Additional name-value arguments
If a driving scenario contains the trajectory of a vehicle with front-axle
steering, you can now use the ShowRearAxle
name-value argument
to plot its rear-axle trajectory.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)