poly2ccw

Convert polygon contour to counterclockwise vertex ordering

Syntax

[x2,y2] = poly2ccw(x1,y1)

Description

[x2,y2] = poly2ccw(x1,y1) arranges the Cartesian vertices in the polygonal contour (x1,y1) in counterclockwise order, returning the result in x2 and y2. If x1 and y1 can contain multiple contours, represented either as NaN-separated vectors or as cell arrays, then each contour is converted to clockwise ordering. x2 and y2 have the same format (NaN-separated vectors or cell arrays) as x1 and y1.

Examples

Convert a clockwise-ordered square to counterclockwise ordering.

x1 = [0 0 1 1 0];
y1 = [0 1 1 0 0];
ispolycw(x1, y1)

ans =
         1

[x2, y2] = poly2ccw(x1, y1);
ispolycw(x2, y2)
ans =
         0

Tips

You can use poly2ccw for geographic coordinates if the polygon does not cross the Antimeridian or contain a pole. A polygon contains a pole if the longitude data spans 360 degrees. To use poly2ccw with geographic coordinates, specify the longitude vector as x1 and the latitude vector as y1.

Introduced before R2006a