Main Content

ScenarioAnchorPoint

Scenario anchor point

Since R2025a

    Description

    The ScenarioAnchorPoint object represents a scenario anchor defined in the current scenario. You can use a ScenarioAnchorPoint object to specify the positions of other scenario objects, such as actors, and anchor them to roads. For more information on anchors in RoadRunner Scenario, see Scenario Anchoring System (RoadRunner Scenario).

    Creation

    You can use the autoAnchor function to anchor the specified, unanchored point in your scenario to the nearest scene or scenario anchor. If no anchors exist near the specified point, RoadRunner Scenario creates a new anchor that matches the Default Anchor Type setting in the RoadRunner Scenario Application Preferences. By default, this is set to Scenario Anchor.

    The RoadRunner authoring API stores anchor points in the AnchorPoint property of the Point object. To retrieve the ScenarioAnchorPoint object that represents a scenario anchor, extract the AnchorPoint property of the specified point. For example, carPoint = car.InitialPoint extracts the InitialPoint property of the actor car, and scnroAnchor = carPoint.AnchorPoint extracts the AnchorPoint property of that point and assigns it to the variable scnroAnchor.

    Properties

    expand all

    Name of the anchor, specified as a string scalar or character vector.

    Examples

    collapse all

    Use the autoAnchor function to create a new scenario anchor for a route point. Then, extract the ScenarioAnchorPoint object from the newly created anchor.

    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 drop down.

    Open an existing scene in RoadRunner by using the openScene function, specifying the roadrunner object rrApp and the filename of the specific scene that you want to open. Then, use the newScenario function to create a new scenario.

    openScene(rrApp,"ScenarioBasic.rrscene")
    newScenario(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 and scenarios, such as by adding and modifying roads, actors, and logic components, using MATLAB.

    rrApi = roadrunnerAPI(rrApp);
    
    Extract the scene and scenario objects from the Scene and Scenario properties of the authoring API object rrApi, respectively. The extracted Scene object enables you to specify the scene in which to add scene components such as roads and lanes. The extracted Scenario (RoadRunner Scenario) object enables you to specify the scenario in which to add scenario components such as actors and logic.
    scn = rrApi.Scene;
    scnro = rrApi.Scenario;
    Extract the object for your RoadRunner project from the Project property of the authoring API object rrApi. The extracted Project object enables you to specify the project folder for the current RoadRunner session from which to retrieve asset objects. You can use the asset objects to assign assets to roads in your scene, or to actors in your scenario.
    prj = rrApi.Project;

    Add a Vehicle actor to the scenario. Use the getAsset function to extract a VehicleAsset object, mySedan, that represents the Sedan.fbx asset in the project prj. Then, use the addActor function, specifying the scenario object scnro, the asset object, and the location at which to place the actor. Place the vehicle actor car at the world origin, specified as [0 0 0].

    mySedan = getAsset(prj,"Vehicles/Sedan.fbx","VehicleAsset");
    car = addActor(scnro,mySedan,[0 0 0]);

    If you do not know the exact coordinates at which you want to place the actor, you can relocate the actor based on an existing point or anchor. For example, you can use findSceneAnchor to reference an existing anchor in the scene, then use anchorToPoint to relocate the actor from its current location to the location specified by the referenced anchor.

    anchorPoint = findSceneAnchor(scnro,"ScenarioStart");
    carPoint = car.InitialPoint;
    anchorToPoint(carPoint,anchorPoint,PosePreservation="reset-pose")

    Use autoAnchor to Create Scenario Anchor

    Extract the object that represents the route for car by specifying the Route property of carPoint and assigning it to the variable rrRoute. Then, use the addPoint function to add a new point, rrPoint, to the route at [0 0 0].

    rrRoute = carPoint.Route;
    rrPoint = addPoint(rrRoute,[0 0 0]);
    

    Use autoAnchor to anchor the new point to the road, and specify "preserve-pose" as the pose preservation option to retain the current position and tangent heading of rrPoint. Because there is no existing anchor near rrPoint, RoadRunner Scenario creates a new scenario anchor.

    autoAnchor(rrPoint,PosePreservation="preserve-pose")

    Retrieve the ScenarioAnchorPoint object for the newly created scenario anchor by extracting the AnchorPoint property of the Point object rrPoint. You can use the scenario anchor object scnroAnchor to specify positions for the actors and anchor them to roads in your scenario. For more information, see anchorToPoint.

    scnroAnchor = rrPoint.AnchorPoint;

    Version History

    Introduced in R2025a