# ispolycw

True if polygon vertices are in clockwise order

## Syntax

```tf = ispolycw(x,y) ```

## Description

`tf = ispolycw(x,y)` returns true if the polygonal contour vertices represented by `x` and `y` are ordered in the clockwise direction. `x` and `y` are Cartesian vectors with the same number of elements.

Alternatively, `x` and `y` can contain multiple contours, either in `NaN`-separated vector form or in cell array form. In that case, `ispolycw` returns a logical array containing one true or false value per contour.

`ispolycw` always returns true for polygonal contours containing two or fewer vertices.

Vertex ordering is not well defined for self-intersecting polygonal contours. For such contours, `ispolycw` returns a result based on the order or vertices immediately before and after the left-most of the lowest vertices. In other words, of the vertices with the lowest `y` value, find the vertex with the lowest `x` value. For a few special cases of self-intersecting contours, the vertex ordering cannot be determined using only the left-most of the lowest vertices; for these cases, `ispolycw` uses a signed area test to determine the ordering.

## Class Support

`x` and `y` may be any numeric class.

## Examples

Orientation of a square:

```x = [0 1 1 0 0]; y = [0 0 1 1 0]; ispolycw(x, y) % Returns 0 ispolycw(fliplr(x), fliplr(y)) % Returns 1```

## Tips

You can use `ispolycw` 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 `ispolycw` with geographic coordinates, specify the longitude vector as `x` and the latitude vector as `y`.

## Version History

Introduced before R2006a