主要内容

addJunction

R2026b

Add junction to RoadRunner scene

Since R2026b

    Description

    rrJunction = addJunction(scn,rrRoads,startDistances,endDistances) adds a junction to the current RoadRunner scene by connecting one or more roads at specified start and end distances along each road. It automatically creates corner geometry at the junction boundaries and returns a Junction object that represents the road connection. Optionally, the function can create maneuver roads automatically, apply a specified corner radius to all corners, and clear existing lane markings within the junction. The Junction object also provides access to the corners, maneuvers, and lane connections associated with the new intersection.

    example

    rrJunction = addJunction(scn,rrRoads,startDistances,endDistances,Name=Value) adds a junction to the current RoadRunner scene by using optional name-value arguments. Using the optional name-value arguments, the addJunction function can create maneuver roads automatically, apply a specified corner radius to all corners, and clear existing lane markings within the junction.

    Examples

    collapse all

    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 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 dropdown.

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

    newScene(rrApp);

    Create a RoadRunner authoring API object, 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 lane 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 components, such as roads and lanes.
    scn = rrApi.Scene
    

    Use the addSegmentedRoad function to add a segmented curve type road to the scene. Specify the starting point of the road as a control point. Next, indicate the forward direction of the road by specifying a second control point. You must specify the positions of these control points along the X- and Y- axes of the RoadRunner local coordinate system.

    startPoint1 = [0 0];
    startRoadDirection1 = [1 0];
    rrRoad1 = addSegmentedRoad(scn,startPoint1,startRoadDirection1);
    

    Extract the horizontal curve of the segmented road. Then, use the addLine function to create a line segment and add it to the horizontal curve.

    segmentedCurve1 = rrRoad1.HorizontalCurve;
    addLine(segmentedCurve1,100);
    

    Extract the reference lane of the road from the ReferenceLane property of the road object rrRoad1. 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.

    refLane1 = rrRoad1.ReferenceLane;

    Use the extracted refLane1 object to add lane on the left side of the reference lane of the road using the addLaneToLeft function. Then, use the LaneType and TravelDirection properties of the added lane to specify the type and travel direction, respectively. Add a driving lane to the left of the horizontal road with a backward travel direction.

    horizontalLane1 = addLaneToLeft(refLane1);
    horizontalLane1.LaneType = "driving";
    horizontalLane1.TravelDirection = "backward";
    

    Configure the width profile for the left lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane1WidthProfile = horizontalLane1.WidthProfile;
    startNode1 = horizontalLane1WidthProfile.Nodes(1);
    startNode1.EndWidth = 3.5;
    endNode1 = horizontalLane1WidthProfile.Nodes(end);
    endNode1.StartWidth = 3.5;
    

    Use the extracted refLane1 object to add another lane on the right side of the reference lane of the road using the addLaneToRight function. Then, use the LaneType and TravelDirection properties of the lane to specify the type and travel direction, respectively. Add a driving lane to the right of the horizontal road with a forward travel direction.

    horizontalLane2 = addLaneToRight(refLane1);
    horizontalLane2.LaneType = "driving";
    horizontalLane2.TravelDirection = "forward";
    

    Configure the width profile for the right lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane2WidthProfile = horizontalLane2.WidthProfile;
    startNode2 = horizontalLane2WidthProfile.Nodes(1);
    startNode2.EndWidth = 3.5;
    endNode2 = horizontalLane2WidthProfile.Nodes(end);
    endNode2.StartWidth = 3.5;
    

    Use the addSegmentedRoad function to add another segmented curve type road to the scene. Specify the starting point of the road as a control point. Next, indicate the forward direction of the road by specifying a second control point. You must specify the positions of these control points along the X- and Y- axes of the RoadRunner local coordinate system.

    startPoint2 = [110 0];
    startRoadDirection2 = [1 0];
    rrRoad2 = addSegmentedRoad(scn,startPoint2,startRoadDirection2);

    Extract the horizontal curve of the second segmented road. Then, use the addLine function to create a line segment and add it to the second horizontal curve.

    segmentedCurve2 = rrRoad2.HorizontalCurve;
    addLine(segmentedCurve2,100);

    Extract the reference lane of the road from the ReferenceLane property of the road object rrRoad2.

    refLane2 = rrRoad2.ReferenceLane;

    Use the extracted refLane2 object to add lane on the left side of the second reference lane of the road using the addLaneToLeft function. Then, use the LaneType and TravelDirection properties of the added lane to specify the type and travel direction, respectively. Add a driving lane to the left of the second horizontal road with a backward travel direction.

    horizontalLane3 = addLaneToLeft(refLane2);
    horizontalLane3.LaneType = "driving";
    horizontalLane3.TravelDirection = "backward";
    

    Configure the width profile for the second left lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane3WidthProfile = horizontalLane3.WidthProfile;
    startNode3 = horizontalLane3WidthProfile.Nodes(1);
    startNode3.EndWidth = 3.5;
    endNode3 = horizontalLane3WidthProfile.Nodes(end);
    endNode3.StartWidth = 3.5;
    

    Use the extracted refLane2 object to add another lane on the right side of the reference lane of the road using the addLaneToRight function. Then, use the LaneType and TravelDirection properties of the lane to specify the type and travel direction, respectively. Add a driving lane to the right of the second horizontal road with a forward travel direction.

    horizontalLane4 = addLaneToRight(refLane2);
    horizontalLane4.LaneType = "driving";
    horizontalLane4.TravelDirection = "forward";
    

    Configure the width profile for the second right lane by specifying the WidthProfile property of the lane. Specify the width of the lane.

    horizontalLane4WidthProfile = horizontalLane4.WidthProfile;
    startNode4 = horizontalLane4WidthProfile.Nodes(1);
    startNode4.EndWidth = 3.5;
    endNode4 = horizontalLane4WidthProfile.Nodes(end);
    endNode4.StartWidth = 3.5;
    

    Create a junction at distance ranges specified by startDistances and endDistances. You must specify these distance ranges as control points along the X- and Y- axes of the RoadRunner local coordinate system.

    roads = [rrRoad1, rrRoad2];
    startDistances = [90, -1];
    endDistances = [-1, 10];
    rrJunction = addJunction(scn, roads, startDistances, endDistances);
    

    Input Arguments

    collapse all

    Current RoadRunner scene, specified as a Scene object.

    Roads in the junction in a RoadRunner scene, specified as an array of Road objects. Each road must have a corresponding start and end distance value that defines the part of the road included in the junction.

    Junction start location on the road, specified as a positive numeric matrix. This indicates the start distances along each road where the junction begins. Use -1 or Inf to indicate that a road starts inside the junction.

    Data Types: double

    Junction start location on the road, specified as a positive numeric matrix. This indicates the end distances along each road where the junction ends. Use -1 or Inf to indicate that a road ends inside the junction.

    Data Types: double

    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.

    Example: addJunction(scn,rrRoads, startDistances, endDistances, CreateManeuvers="true")

    Signal for automatic maneuver creation, specified as true or 1 or false or 0. When set to true, it automatically creates maneuver roads using heuristic lane mapping between compatible lanes after the junction is created. Existing maneuvers are preserved. RoadRunner preserves existing maneuvers while creating automatic maneuvers.

    Data Types: bool

    Radius applied to every corner after RoadRunner creates the junction, specified as a positive scalar. Units are in meters. Use -1 as the corner radius value to keep the automatically computed corner radii.

    Data Types: double

    Extent to which to clear lane markings, specified as one of these values listed in the table.

    ValueDescription
    "skip"RoadRunner leaves all markings unchanged in the junction.
    "stoplines"RoadRunner clears markings only till the stopline position from the junction.
    "all"RoadRunner clears all lane markings within the junction including corners.

    Data Types: string

    Output Arguments

    collapse all

    Junction in RoadRunner scene, specified as a Junction object.

    Version History

    Introduced in R2026b