Utilities for working with polygons.
Provides functions for computing polygon properties like area, centroid, perimeter, and convex hull.
Examples
polygon = [{0, 0}, {100, 0}, {100, 100}, {0, 100}]
Visualize.Polygon.area(polygon) # => 10000.0
Visualize.Polygon.centroid(polygon) # => {50.0, 50.0}
Visualize.Polygon.perimeter(polygon) # => 400.0
# Convex hull of scattered points
points = [{0, 0}, {50, 50}, {100, 0}, {100, 100}, {0, 100}]
Visualize.Polygon.hull(points) # => [{0, 0}, {100, 0}, {100, 100}, {0, 100}]
Summary
Functions
Computes the signed area of a polygon.
Computes the bounding box of a polygon.
Computes the centroid (center of mass) of a polygon.
Tests if a point is inside a polygon.
Computes the convex hull of a set of points.
Computes the length of a polyline (open path).
Computes the perimeter (total edge length) of a polygon.
Types
Functions
Computes the signed area of a polygon.
Returns a positive value for counter-clockwise polygons,
negative for clockwise. Use abs/1 if you need the absolute area.
Uses the shoelace formula.
Computes the bounding box of a polygon.
Returns {min_x, min_y, max_x, max_y}.
Computes the centroid (center of mass) of a polygon.
Returns the geometric center of the polygon.
Tests if a point is inside a polygon.
Uses the ray casting algorithm.
Computes the convex hull of a set of points.
Returns the vertices of the convex hull in counter-clockwise order. Uses Andrew's monotone chain algorithm.
Computes the length of a polyline (open path).
Unlike perimeter/1, this doesn't close the polygon.
Computes the perimeter (total edge length) of a polygon.