Main Content

Lane

Lane on road in RoadRunner scene

Since R2025a

    Description

    The Lane object represents a lane on a road in the current RoadRunner scene. You can use the Lane object to programmatically add lanes and modify lane attributes such as the type and travel direction of the lane. You can also specify lane markings and the width of the outer boundary of the lane.

    Creation

    You can create a Lane object in these ways:

    • To retrieve a Lane object from your RoadRunner scene, extract the Lanes property of the road object. For example, rrLane1 = rrRoad.Lanes(1) extracts the first Lane object from the Lanes property of the road rrRoad.

    • You can use the addLaneToLeft or addLaneToRight functions to add a new lane to the left side or right side of an existing lane, respectively, relative to the road direction.

    Properties

    expand all

    Travel direction of the lane, specified as one of the values listed in the table.

    ValueDescription
    "Undirected"Vehicles can travel along any direction on the road.
    "Forward"Vehicles travel in the forward direction of the road. For example, if you set this lane direction on a road that runs from left to right, vehicles can only move forward along the lane, from left to right.
    "Backward"Vehicles travel in the backward direction of the road. For example, if you set this lane direction on a road that runs from left to right, vehicles can only move backward along the lane, from right to left.
    "Bidirectional"Vehicles can travel in both the forward and backward directions of the road.

    Type of lane, specified as one of the values listed in this table.

    ValueDescription
    "Driving"Normal lane intended for vehicle travel and not reserved for any other purpose.
    "Biking"Lane reserved for cyclists.
    "Shoulder"Lane representing a soft border at the edge of the road. This lane is reserved for emergency stopping or vehicle breakdowns.
    "Border" Lane representing the hard border at the edge of the road, adjacent to the road boundary. Vehicles are not permitted to cross beyond this lane.
    "Restricted"Lane reserved for high occupancy vehicles.
    "Center Turn"Lane in the middle of a two-way street, intended for making a turn.
    "Median"Nondriving lane between two driving lanes with opposite travel directions.
    "Raised Median"Median with a raised area between two driving lanes with opposite travel directions.
    "Curb"Lane representing the curb at the edge of the road. Vehicles often stop in this lane to pick up or drop off passengers.
    "Sidewalk"Lane reserved for pedestrians.
    "Parking"Lane alongside a driving lane, intended for vehicles to park in.
    "Stop"Lane for emergency stops on a highway.
    "Road Works"Nondriving lane, used to specify road works lane closures.
    "Tram"Lane reserved for trams.
    "Rail"Lane reserved for light rail vehicles.
    "Entry"Acceleration lane parallel to driving lanes.
    "Exit"Deceleration lane parallel to driving lanes.
    "Off Ramp"Ramp to exit a highway and go to a local road.
    "On Ramp"Ramp to enter a highway from a local road.
    "None"Nondriving lane, used to specify space on the outermost edge of the road.

    This property is read-only.

    Width profile of the lane, represented as a LaneWidthProfile object. The width profile of a lane defines the geometry of the outer boundary of the lane.

    This property is read-only.

    Lane marking profile for the lane, represented as a LaneMarkingProfile object. The marking profile of a lane defines the markings on the outer boundary of the lane.

    Object Functions

    addLaneToRightAdd lane to right side of specified lane
    addLaneToLeftAdd lane to left side of specified lane

    Examples

    collapse all

    Create a RoadRunner scene with a single horizontal road and add two driving lanes with opposite travel directions.

    Create a roadrunner object, specifying the path to an existing project. For example, this code shows the path to a project, on a Windows® machine, located at "C:\RR\MyProject". This code assumes that RoadRunner is installed in the default location, and returns an object, rrApp, that provides functions for performing basic tasks such as opening, closing, and saving scenes and projects.

    rrApp = roadrunner(ProjectFolder="C:\RR\MyProject");

    Note: If you are opening RoadRunner from MATLAB® for the first time, or if you have changed the RoadRunner installation location since you last opened it from MATLAB, you can use the roadrunnerSetup (RoadRunner) function to specify new default project and installation folders to use when opening RoadRunner. You can save these folders between MATLAB sessions by selecting the Across MATLAB sessions option from the corresponding drop down.

    Create a new RoadRunner scene in the current project by using the newScene function, specifying the roadrunner object rrApp.

    newScene(rrApp);

    Create an object for the RoadRunner authoring API, rrApi, that references the object for the current RoadRunner instance rrApp. The rrApi object enables you to programmatically author scenes, such as by adding and modifying road and lanes components, using MATLAB.

    rrApi = roadrunnerAPI(rrApp);

    Extract the object for your scene from the Scene property of the authoring API object rrApi. The extracted Scene object enables you to specify the scene in which to add scene elements such as roads and lanes.

    scn = rrApi.Scene;

    Add a horizontal line-arc curve road 100 meters in length to the scene by using the addLineArcRoad function. Specify the positions of the road by specifying the positions of its control points along the X- and Y-axes of the RoadRunner local coordinate system. These control points define the positions of the start and end of the road. You can modify the positions of the control points to adjust the length and direction of the road relative to the scene origin. You can also add control points in between the start and end points of the line-arc curve to adjust the curvature and radius of the road curve.

    controlPoints = [-50 0; 50 0];
    rrHorizontalRoad = addLineArcRoad(scn,controlPoints);

    Extract the reference lane of the road from the ReferenceLane property of the road object rrHorizontalRoad. The reference lane defines the center lane, or reference line, of a road in a RoadRunner scene. This lane has no width and serves as the basis for positioning all other lanes, which RoadRunner arranges outward from the reference line.

    refLane = rrHorizontalRoad.ReferenceLane;

    Roadrunner scene canvas with a reference lane

    Use the extracted refLane object to add lanes on either side of the reference lane of the road using the addLaneToLeft and addLaneToRight functions. Then, use the LaneType and TravelDirection properties of the added lanes to specify the type and travel direction, respectively, of each lane. First, add a driving lane to the left of the horizontal road with a forward travel direction.

    horizontalLane1 = addLaneToLeft(refLane);
    horizontalLane1.LaneType = "Driving";
    horizontalLane1.TravelDirection = "Forward";

    Roadrunner scene canvas with a driving lane to the left of the reference lane

    Then, add another driving lane to the right of the horizontal road with a backward travel direction.

    horizontalLane2 = addLaneToRight(refLane);
    horizontalLane2.LaneType = "Driving";
    horizontalLane2.TravelDirection = "Backward";

    Roadrunner scene canvas with two driving lanes, one with a forward and one with a backward travel direction

    Version History

    Introduced in R2025a