grains.cad.polygon_orientation¶
-
grains.cad.polygon_orientation(polygon)[source]¶ Determines whether a polygon is oriented clockwise or counterclockwise.
- Parameters
polygon (list) – Each element of the list denotes a vertex of the polygon and in turn is another list of two elements: the x and y coordinates of a vertex.
- Returns
orientation ({‘cw’, ‘ccw’}) – ‘cw’: clockwise, ‘ccw’: counterclockwise orientation
Notes
The formula to determine the orientation is from https://stackoverflow.com/a/1165943/4892892. For simple polygons (polygons that admit a well-defined interior), a faster algorithm exits, see https://en.wikipedia.org/wiki/Curve_orientation#Orientation_of_a_simple_polygon.
Examples
>>> polygon = [[5, 0], [6, 4], [4, 5], [1, 5], [1, 0]] >>> polygon_orientation(polygon) 'ccw'