Polygon.jl

Polygon provides a ConvexHull type, which represents the convex hull of a set of 2D points by its extreme points. Functionality includes:

  • convexity test
  • construction of a convex hull given a set of points
  • area
  • centroid
  • point-in-convex-hull test
  • closest point within convex hull
  • equivalent halfspace representation of the convex hull

Types

The ConvexHull type

Polygon.ConvexHullType
struct ConvexHull{O<:Polygon.VertexOrder, T, P<:StaticArraysCore.StaticArray{Tuple{2}, T, 1}, V<:AbstractArray{P<:StaticArraysCore.StaticArray{Tuple{2}, T, 1}, 1}}

Represents the convex hull of a set of 2D points by its extreme points (vertices), which are stored according to the VertexOrder given by the first type parameter.

source
Polygon.SConvexHullType
SConvexHull{N, T}

The default statically-sized ConvexHull type. Backed by an SVector{N, SVector{2, T}} with vertices ordered counter-clockwise.

source
Polygon.DConvexHullType
DConvexHull{N, T}

The default dynamically-sized ConvexHull type. Backed by a Vector{SVector{2, T}} with vertices ordered counter-clockwise.

source

VertexOrders

Polygon.CCWType
struct CCW <: Polygon.VertexOrder

Counterclockwise vertex order.

source
Polygon.CWType
struct CW <: Polygon.VertexOrder

Clockwise vertex order.

source

Algorithms

Polygon.centroidFunction
centroid(hull)

Compute the centroid or geometric center of the given ConvexHull using the formulas given here.

source
Base.inMethod
in(point, hull)

Return whether point is in hull.

source
Polygon.closest_pointFunction
closest_point(p, hull)

Find the closest point to p within hull. If p is inside hull, p itself is returned.

source
Polygon.hrepFunction
hrep(hull)

Return the equivalent halfspace representation of the convex hull, i.e. matrix $A$ and vector $b$ such that the set of points inside the hull is

\[\left\{ x \mid A x \le b \right\}\]

If hull is backed by a statically sized vector of vertices, the output (A, b) will be statically sized as well. If the vector of vertices is additionally immutable (e.g., a StaticArrays.SVector), then hrep will not perform any dynamic memory allocation.

source
Polygon.hrep!Function
hrep!(A, b, hull)

Return the equivalent halfspace representation of the convex hull, i.e. matrix $A$ and vector $b$ such that the set of points inside the hull is

\[\left\{ x \mid A x \le b \right\}\]

This function stores its output in the (mutable) matrix A and vector b.

source