Main Content

poly2ccw

Convert polygon vertices to counterclockwise order

    Description

    [x2,y2] = poly2ccw(x1,y1) arranges the Cartesian vertices of the polygon defined by x1 and y1 so the vertices are in counterclockwise order.

    example

    Examples

    collapse all

    Specify a polygon using vertices in clockwise order. Close the polygon by repeating the first vertex at the end of the list.

    x1 = [0 1 4 3 0];
    y1 = [0 1 3 2 0];
    ispolycw(x1,y1)
    ans = logical
       1
    
    

    Arrange the vertices so they are in counterclockwise order.

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

    Input Arguments

    collapse all

    x-coordinates of the polygon, specified as a numeric vector or a cell array of numeric vectors.

    • Define one polygon by specifying a vector, such as [39 45 19 39].

    • Define multiple polygons by using one of these options:

      • Specify a vector and separate the polygons using NaN values, such as [37 46 31 20 37 NaN 45 49 35 32 45 NaN 35 40 42 35]. The NaN values in x1 must correspond to the NaN values in y1.

      • Specify a cell array of vectors, such as {[37 46 31 20 37],[45 49 35 32 45],[35 40 42 35]}. The size of the vector in each cell of x1 must match the size of the vector in the corresponding cell of y1.

    The size and type of x1 must match the size and type of y1.

    y-coordinates of the polygon, specified as a numeric vector or a cell array of numeric vectors.

    • Define one polygon by specifying a vector, such as [-113 -49 -100 -113].

    • Define multiple polygons by using one of these options:

      • Specify a vector and separate the polygons using NaN values, such as [69 90 105 79 69 NaN 6 52 43 14 6 NaN 18 32 22 18]. The NaN values in y1 must correspond to the NaN values in x1.

      • Specify a cell array of vectors, such as {[69 90 105 79 69],[6 52 43 14 6],[18 32 22 18]}. The size of the vector in each cell of y1 must match the size of the vector in the corresponding cell of x1.

    The size and type of y1 must match the size and type of x1.

    Output Arguments

    collapse all

    x-coordinates in counterclockwise order, returned as a numeric vector or a cell array of numeric vectors.

    When x1 and y1 define multiple polygons, the poly2ccw function converts the coordinates of each individual polygon to counterclockwise order.

    The size and type of x2 matches the size and type of x1.

    Data Types: double

    y-coordinates in counterclockwise order, returned as a numeric vector or a cell array of numeric vectors.

    When x1 and y1 define multiple polygons, the poly2ccw function converts the coordinates of each individual polygon to counterclockwise order.

    The size and type of y2 matches the size and type of y1.

    Data Types: double

    Tips

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

    Version History

    Introduced before R2006a