Main Content

laneMarking

Create road lane marking object

Description

Single Marking Type Along Lane

lm = laneMarking(type) creates a default lane marking object of the specified type (solid lane, dashed lane, and so on). This object defines the characteristics of a lane boundary marking on a road. When creating roads in a driving scenario, you can use lane marking objects as inputs to the lanespec object.

lm = laneMarking(type,Name,Value) set the properties of the lane marking object using one or more name-value pairs. For example, laneMarking('Solid','Color','yellow') creates a solid yellow lane marking.

example

Multiple Marking Types Along Lane

cm = laneMarking(lmArray) creates a composite lane marking object from an array of lane marking objects, lmArray. Use this syntax to generate lane markings that contain multiple marker types.

For example, create a lane boundary marking that has both solid and dashed marking types by defining lmArray.

lmArray = [laneMarking('Solid') laneMarking('Dashed')]
cm = laneMarking(lmArray)
The order in which the marking types occur depend on the draw direction of the road. For more information, see Draw Direction of Road and Numbering of Lanes and Composite Lane Marking.

example

cm = laneMarking(lmArray,'SegmentRange',range) specifies the range for each marker type in the composite lane marking by using the name-value pair argument 'SegmentRange', range.

example

Examples

collapse all

Create a driving scenario and the road centers for a straight, 80-meter road.

scenario = drivingScenario;
roadCenters = [0 0; 80 0];

Create a lanespec object for a four-lane road. Use the laneMarking function to specify its five lane markings. The center line is double-solid and double yellow. The outermost lines are solid and white. The inner lines are dashed and white.

solidW = laneMarking('Solid','Width',0.3);
dashW = laneMarking('Dashed','Space',5);
doubleY = laneMarking('DoubleSolid','Color','yellow');
lspec = lanespec([2 2],'Width',[5 5 5 5], ...
    'Marking',[solidW dashW doubleY dashW solidW]);

Add the road to the driving scenario. Display the road.

road(scenario,roadCenters,'Lanes',lspec);
plot(scenario)

Figure contains an axes object. The axes object with xlabel X (m), ylabel Y (m) contains 3 objects of type patch, line.

Simulate a driving scenario with one car traveling on an S-curve. Create and plot the lane boundaries.

Create the driving scenario with one road having an S-curve.

scenario = drivingScenario('StopTime',3);
roadcenters = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];

Create the lanes and add them to the road.

lm = [laneMarking('Solid','Color','w'); ...
    laneMarking('Dashed','Color','y'); ...
    laneMarking('Dashed','Color','y'); ...
    laneMarking('Solid','Color','w')];
ls = lanespec(3,'Marking',lm);
road(scenario,roadcenters,'Lanes',ls);

Add an ego vehicle and specify its trajectory from its waypoints. By default, the car travels at a speed of 30 meters per second.

car = vehicle(scenario, ...
    'ClassID',1, ...
    'Position',[-35 20 0]);
waypoints = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];
smoothTrajectory(car,waypoints);

Plot the scenario and corresponding chase plot.

plot(scenario)

chasePlot(car)

Run the simulation loop.

  1. Initialize a bird's-eye plot and create an outline plotter, left-lane and right-lane boundary plotters, and a road boundary plotter.

  2. Obtain the road boundaries and rectangular outlines.

  3. Obtain the lane boundaries to the left and right of the vehicle.

  4. Advance the simulation and update the plotters.

bep = birdsEyePlot('XLim',[-40 40],'YLim',[-30 30]);
olPlotter = outlinePlotter(bep);
lblPlotter = laneBoundaryPlotter(bep,'Color','r','LineStyle','-');
lbrPlotter = laneBoundaryPlotter(bep,'Color','g','LineStyle','-');
rbsEdgePlotter = laneBoundaryPlotter(bep);
legend('off');
while advance(scenario)
    rbs = roadBoundaries(car);
    [position,yaw,length,width,originOffset,color] = targetOutlines(car);
    lb = laneBoundaries(car,'XDistance',0:5:30,'LocationType','Center', ...
        'AllBoundaries',false);
    plotLaneBoundary(rbsEdgePlotter,rbs)
    plotLaneBoundary(lblPlotter,{lb(1).Coordinates})
    plotLaneBoundary(lbrPlotter,{lb(2).Coordinates})
    plotOutline(olPlotter,position,yaw,length,width, ...
        'OriginOffset',originOffset,'Color',color)
end

This example shows how to create a driving scenario for maneuvers such as changing lanes and passing other vehicles. You create roads with passing zones and add vehicles to the scenario. Then, define the trajectories for these vehicles to simulate vehicle lane change in passing zones.

Create Road with Passing Zones by Using Composite Lane Marking

Create a driving scenario. Specify the road centers and the number of lanes to add a two-way, two-lane straight road of 54 meters with draw direction from top-to-bottom.

scenario = drivingScenario('StopTime',10);
roadCenters = [50 0; -4 0];
numLanes = [1 1];

Typically, the number of lane markings is equal to number of lanes plus one. A two-way, two-lane road has 3 lane markings and the outermost lane markings at both the edges are solid white lines.

Create a solid marking object of marking width 0.25 meters, to constitute the outermost lane markings for the two-way road.

outerLM = laneMarking('Solid','Width',0.25);

Create a lane marking array of SolidMarking and DashedMarking objects that contain the properties for solid and dashed double yellow lines.

lmArray = [laneMarking('DoubleSolid','Color','Yellow','Width',0.25)
           laneMarking('DashedSolid','Color','Yellow','Length',1,'Space',1.5,'Width',0.25)
           laneMarking('DoubleSolid','Color','Yellow','Width',0.25)
           laneMarking('SolidDashed','Color','Yellow','Length',1,'Space',1.5,'Width',0.25)];

Create a composite lane marking object for the center lane marking by using the lane marking array. Specify the normalized length for each marking object.

centerLM = laneMarking(lmArray,'SegmentRange',[0.1 0.25 0.2 0.35]);

Create a vector of the outermost and the center lane marking objects. Pass the vector as input to the lanespec function in order to define the lane specifications of the road.

marking = [outerLM centerLM outerLM];
ls = lanespec(numLanes,'Width',7,'Marking',marking);

Add the road to the driving scenario. Plot the driving scenario. Since the draw direction of the road is from top-to-bottom, the marking types in the composite lane marking also occur in top-to-bottom order.

road(scenario,roadCenters,'Lanes',ls);
figMark = figure;
set(figMark,'Position',[0 0 600 600]);
hPlot = axes(figMark);
plot(scenario,'Parent',hPlot);
title('Composite Marking: Road with Passing Zones')

Figure contains an axes object. The axes object with title Composite Marking: Road with Passing Zones, xlabel X (m), ylabel Y (m) contains 3 objects of type patch, line.

Simulate Vehicle Lane Change in Passing Zones

Add a slow moving vehicle (SMV) to the scenario. Specify the waypoints and speed value to set the trajectory for the SMV.

slowVehicle = vehicle(scenario,'ClassID',1,'Position',[37 -3 0]);
waypoints = [37 -3;12 -3];
speed = 2;
smoothTrajectory(slowVehicle,waypoints,speed);

Add another vehicle to the scenario. Set the trajectory for the vehicle in such a way that it passes the SMV in front of it by changing lanes at the passing zones.

passingVehicle = vehicle(scenario,'ClassID',1,'Position',[49 -3 0]);
waypoints = [49 -3; 45 -3; 40 -3; 35 0;
             30 3; 26 3; 22 3; 18 3;
             8 0; 5 -2; 2 -3; 1 -3];
speed = 6;
smoothTrajectory(passingVehicle,waypoints,speed);

Create a custom figure window and plot the scenario.

close all;
figScene = figure;
set(figScene,'Position',[0 0 600 600]);
hPanel = uipanel(figScene);
hPlot = axes(hPanel);
plot(scenario,'Parent',hPlot);
title('Passing Zone: Change Lane and Pass Other Vehicle')

% Run the simulation
while advance(scenario)
    pause(0.01)
end

Figure contains an axes object and an object of type uipanel. The axes object with title Passing Zone: Change Lane and Pass Other Vehicle, xlabel X (m), ylabel Y (m) contains 5 objects of type patch, line.

Input Arguments

collapse all

Type of lane marking, specified as one of these values.

'Unmarked' 'Solid''Dashed''DoubleSolid''DoubleDashed''SolidDashed''DashedSolid'

No lane marking

Solid line

Dashed line

Two solid lines

Two dashed lines

Solid line on left, dashed line on right

Dashed line on left, solid line on right

Sample of an unmarked lane

Sample of a solid lane marking

Sample of a dashed lane marking

Sample of a double-solid lane marking

Sample of a double-dashed lane marking

Sample of a solid-dashed lane marking

Sample of a dashed-solid lane marking

The type of lane marking is stored in Type, a read-only property of the returned lane marking object.

1-D array of lane marking objects, specified as

  • LaneMarking object for 'Unmarked' type of lane marking.

  • SolidMarking object for 'Solid' and 'DoubleSolid' types of lane marking.

  • DashedMarking object for 'Dashed', 'DoubleDashed', 'SolidDashed', and 'DashedSolid' types of lane marking.

Example: lmArray = [laneMarking('Solid') laneMarking('Dashed')]

Range for each marking type, specified as a vector with normalized values in the interval [0, 1]. The length of the vector must be same as the number of marking types specified in the input array lmArray.

The default range value for each marking type in the lane is the inverse of the number of marking types specified in lmArray.

For example, if the input lane marking array contains three lane marking objects, such as lmArray = [laneMarking('Solid') laneMarking('Dashed') laneMarking('Solid')], then the default range value for each marking type is 1/3, that is range = [0.3330 0.3330 0.3330].

Name-Value Arguments

collapse all

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: laneMarking('Dashed','Width',0.25,'Length',5.0) creates a lane with dashes that are 0.25 meters wide and spaced 5 meters apart.

Lane marking widths, specified as the comma-separated pair consisting of 'Width' and a positive real scalar. For a double lane marker, the same width is used for both lines. Units are in meters.

The width of the lane marking must be less than the width of its enclosing lane. The enclosing lane is the lane directly to the left of the lane marking.

Example: 0.20

Color of lane marking, specified as the comma-separated pair consisting of 'Color' and an RGB triplet, a hexadecimal color code, a color name, or a short color name. For a double lane marker, the same color is used for both lines.

For a custom color, specify an RGB triplet or a hexadecimal color code.

  • An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1], for example, [0.4 0.6 0.7].

  • A hexadecimal color code is a string scalar or character vector that starts with a hash symbol (#) followed by three or six hexadecimal digits, which can range from 0 to F. The values are not case sensitive. Therefore, the color codes "#FF8800", "#ff8800", "#F80", and "#f80" are equivalent.

Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and the hexadecimal color codes.

Color NameShort NameRGB TripletHexadecimal Color CodeAppearance
'red''r'[1 0 0]'#FF0000'

Sample of the color red

'green''g'[0 1 0]'#00FF00'

Sample of the color green

'blue''b'[0 0 1]'#0000FF'

Sample of the color blue

'cyan' 'c'[0 1 1]'#00FFFF'

Sample of the color cyan

'magenta''m'[1 0 1]'#FF00FF'

Sample of the color magenta

'yellow''y'[0.98 0.86 0.36]'#FADB5C'

Sample of the color yellow

'black''k'[0 0 0]'#000000'

Sample of the color black

'white''w'[1 1 1]'#FFFFFF'

Sample of the color white

Example: [0.8 0.8 0.8]

Saturation strength of lane marking color, specified as the comma-separated pair consisting of 'Strength' and a real scalar in the range [0, 1]. A value of 0 corresponds to a marking whose color is fully unsaturated. The marking is gray. A value of 1 corresponds to a marking whose color is fully saturated. For a double lane marking, the same strength is used for both lines.

Example: 0.20

Length of dash in dashed lines, specified as the comma-separated pair consisting of 'Length' and a positive real scalar. For a double lane marking, the same length is used for both lines. The dash is the visible part of a dashed line. Units are in meters.

Example: 2.0

Length of space between the end of one dash and the beginning of the next dash, specified as the comma-separated pair consisting of 'Space' and a positive real scalar. For a double lane marking, the same length is used for both lines. Units are in meters.

Example: 2.0

Output Arguments

collapse all

Lane marking, returned as a LaneMarking object, SolidMarking object, or DashedMarking object. The type of returned object depends on the type of input lane marking specified for the type input.

Input TypeOutput Lane MarkingLane Marking Properties
'Unmarked'

LaneMarking object

  • Type

'Solid'

SolidMarking object

  • Color

  • Width

  • Strength

  • Type

'DoubleSolid'
'Dashed'

DashedMarking object

  • Length

  • Space

  • Color

  • Width

  • Strength

  • Type

'DashedSolid'
'SolidDashed'
'DoubleDashed'

You can set these properties when you create the lane marking object by using the corresponding name-value pairs of the laneMarking function. To update these properties after creation, use dot notation. For example:

lm = laneMarking('Solid');
lm.Width = 0.2;
You can set all properties after creation except Type, which is read-only. For details on the geometric properties of the SolidMarking and DashedMarking objects, see Lane Specifications.

Composite lane marking, returned as a CompositeMarking object with properties Markings and SegmentRange.

Composite Lane Marking PropertiesDescription
MarkingsThis property is an array of lane marking objects that defines the multiple marking types comprising the composite lane marking. The part of the lane marking defined by each lane marking object is a marker segment. This property is read-only.
SegmentRangeThis property specifies the normalized range for each marker segment in the composite lane marking. This property is read-only.

Use this object to specify multiple marking types along a lane. For more details on how to specify composite lane markings and the order of marker segments along the lane, see Composite Lane Marking.

More About

collapse all

Version History

Introduced in R2018a