Main Content

headingFromXY

Compute heading angle from XY-points of path

Since R2023a

    Description

    heading = headingFromXY(path) computes the heading angle heading based on the XY-points of the path path.

    example

    Examples

    collapse all

    Create a binary occupancy map using the mapClutter function.

    rng("default")
    map = mapClutter(5,MapSize=[20,20],MapResolution=1);

    Create a plannerAStarGrid object using the map. Plan a path.

    planner = plannerAStarGrid(map);
    pathXY = plan(planner,[1 1],[18 18],"world");

    Compute the heading angle (orientation of the robot) from the path.

    heading = headingFromXY(pathXY);

    Visualize the heading angle on the path.

    show(map)
    hold on
    plot(pathXY(:,1),pathXY(:,2),".-")
    quiver(pathXY(:,1),pathXY(:,2),cos(heading),sin(heading),0.2)

    Figure contains an axes object. The axes object with title Binary Occupancy Grid, xlabel X [meters], ylabel Y [meters] contains 3 objects of type image, line, quiver.

    Input Arguments

    collapse all

    Path, specified as an N-by-2 matrix, where the first column represents the X-coordinate and the second column represents the Y-coordinate of each point on the path.

    Data Types: single | double

    Output Arguments

    collapse all

    Heading angle, returned as an N-element column vector, in radians. Element N is the same as the element (N-1).

    Extended Capabilities

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    Version History

    Introduced in R2023a

    See Also

    Functions

    Objects