imforge.utils module

imforge.utils.is_clockwise(polygon, check_convexity=False)

Return whether or not given polygon is clockwise oriented or not.

If check_convexity is False (the default), it’s assumed that given polygon is convex, so we only check for orientation based on the first vertex. If check_convexity is True, then we check orientation for all vertices and they must all have the same orientation (i.e. the polygon is convex)

Parameters
  • int]] polygon (list[tuple[int,) – the list of polygon vertices which for we want orientation

  • check_convexity (bool) – specify whether or not we have to check convexity of polygon. If False (the default) we compute orientation based on the first vertex.

Returns

True if polygon is clockwise oriented. False if it is counterclockwise oriented.

Return type

bool

Raises

ValueError

  • if polygon does not contain at least 3 distinct vertices

  • if check_convexity is True, and the polygon is not convex

  • if 3 consecutive vertices of polygon are aligned