Main Content

anchorToPoint

Set specified point as anchor

Since R2025a

    Description

    anchorToPoint(point,anchorPoint) sets the point specified by anchorPoint as the new anchor for the point point.

    anchorToPoint(point,anchorPoint,PosePreservation=posePreservation) sets additional options to preserve the current position and tangent heading of the reanchored point point.

    Examples

    collapse all

    Use the anchorToPoint function to relocate an actor in your scenario by specifying an existing scene anchor point as the anchor for the Point property of the actor.

    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]);

    Relocate the actor to a new position on the road by referencing the location of one of the existing scene anchors. Use the findSceneAnchor function to extract the object for an existing anchor, "ScenarioStart", in the scene. anchorPoint represents the anchor "ScenarioStart", and carPoint represents the Point property of car. Use anchorToPoint to relocate the actor from its current location, specified by carPoint, to the location specified by the referenced anchor anchorPoint.

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

    Run the simulation by using the simulateScenario function.

    simulateScenario(rrApp)

    Input Arguments

    collapse all

    Point to anchor, specified as a Point object.

    Example: anchorToPoint(carPoint,anchorPoint,PosePreservation="reset-pose") anchors carPoint to anchorPoint while resetting the position and tangent heading of carPoint.

    Point to serve as the anchor for the point specified by point, specified as one of these objects:

    • Point — Represents a point on a route that defines a location and orientation.

    • SceneAnchorPoint — Represents an anchor defined in the associated scene.

    • ScenarioAnchorPoint — Represents an anchor defined in this scenario.

    Option to preserve the current position and tangent heading of the point, specified as one of these options:

    • "reset-pose" — Resets the position and tangent heading of the point after anchoring.

    • "preserve-pose" — Preserves the position and tangent heading of the point after anchoring.

    Version History

    Introduced in R2025a