Compute heading angle from XY-points of path

Since R2023a

Syntax

``heading = headingFromXY(path)``

Description

example

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

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)```

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

Version History

Introduced in R2023a