Polygon¶
- detroit.polygon_area(polygon: list[tuple[float, float]]) float¶
Returns the signed area of the specified polygon. If the vertices of the polygon are in counterclockwise order (assuming a coordinate system where the origin is in the top-left corner), the returned area is positive; otherwise it is negative, or zero.
- Parameters:
polygon (list[Point2D]) – Polygon
- Returns:
Signed area of the specified polygon
- Return type:
float
Examples
>>> d3.polygon_area([[1, 1], [1.5, 0], [2, 1]]) -0.5
- detroit.polygon_centroid(polygon: list[tuple[float, float]]) tuple[float, float]¶
Returns the centroid of the specified polygon.
- Parameters:
polygon (list[Point2D]) – Polygon
- Returns:
Centroid point
- Return type:
Point2D
Examples
>>> d3.polygon_centroid([[1, 1], [1.5, 0], [2, 1]]) [1.5, 0.6666666666666666]
- detroit.polygon_contains(polygon: list[tuple[float, float]], point: tuple[float, float]) bool¶
Returns
Trueif and only if the specified point is inside the specified polygon.- Parameters:
polygon (list[Point2D]) – Polygon
point (Point2D) – 2D Point
- Returns:
Trueif and only if the specified point is inside the specified polygon.- Return type:
bool
Examples
>>> d3.polygon_contains([[1, 1], [1.5, 0], [2, 1]], [1.5, 0.667]) True
- detroit.polygon_hull(points: list[tuple[float, float]]) list[tuple[float, float]] | None¶
Returns the convex hull of the specified points using Andrew’s monotone chain algorithm. The returned hull is represented as an array containing a subset of the input points arranged in counterclockwise order. Returns
Noneif points has fewer than three elements.- Parameters:
points (list[Point2D]) – List of points
- Returns:
Convex hull or
Noneifpointshas fewer than three elements.- Return type:
list[Point2D] | None
Examples
>>> points = [ ... [2, 2], ... [6, 8], ... [10, 10], ... [12, 10], ... [14, 4], ... [20, 4], ... [24, 8], ... [29, 6], ... [32, 4], ... [35, 5], ... [38, 2], ... ] >>> d3.polygon_hull(points) [[38, 2], [2, 2], [6, 8], [10, 10], [12, 10], [24, 8], [35, 5]]
- detroit.polygon_length(polygon: list[tuple[float, float]]) float¶
Returns the length of the perimeter of the specified polygon.
- Parameters:
polygon (list[Point2D]) – Polygon
- Returns:
Length of the perimeter of the specified polygon.
- Return type:
float
Examples
>>> d3.polygon_length([[1, 1], [1.5, 0], [2, 1]]) 3.23606797749979