Package micycle.pgs
Class PGS_Hull
java.lang.Object
micycle.pgs.PGS_Hull
Generates various types of geomtric hulls (convex, concave, etc.) for
polygons and point sets.
A hull is the smallest enclosing shape of some nature that contains all points in a set.
- Since:
- 1.3.0
- Author:
- Michael Carleton
-
Method Summary
Modifier and TypeMethodDescriptionstatic processing.core.PShapeboundingBox(processing.core.PShape shape) Calculates the bounding box (envelope) for the givenPShapeand returns it as a newPShape.static processing.core.PShapeboundingBox(processing.core.PShape shape, double[] out) Computes the bounding box (envelope) of the givenPShapeand writes its coordinates to the provided array.static processing.core.PShapeconcaveHull(processing.core.PShape shapeSet, double concavity, boolean tight) Constructs a concave hull of a set of polygons, respecting the polygons as constraints (i.e. the hull is guaranteed to contain the polygons).static processing.core.PShapeconcaveHullBFS(List<processing.core.PVector> points, double edgeLengthRatio) Computes the concave hull of a point set using a breadth-first method.static processing.core.PShapeconcaveHullBFS2(List<processing.core.PVector> points, double threshold) Computes the concave hull of a point set using a different algorithm.static processing.core.PShapeconcaveHullDFS(List<processing.core.PVector> points, double concavity) Computes the concave hull of a point set using a depth-first method.static processing.core.PShapeconvexHull(Collection<processing.core.PVector> points) Computes the convex hull of a point set (the smallest convex polygon that contains all the points).static processing.core.PShapeconvexHull(processing.core.PShape shape) Computes the convex hull of the vertices from the input shape (the smallest convex polygon that contains all the shape's vertices).static processing.core.PShapesnapHull(processing.core.PShape shape, double convexity) Computes a hull, having a variable level of convexity, of a shape.
-
Method Details
-
boundingBox
public static processing.core.PShape boundingBox(processing.core.PShape shape) Calculates the bounding box (envelope) for the givenPShapeand returns it as a newPShape.The returned shape represents the axis-aligned bounding rectangle that contains the input shape.
- Parameters:
shape- the input shape for which to compute the bounding box- Returns:
- a
PShaperepresenting the bounding box of the input shape - Since:
- 2.1
-
boundingBox
public static processing.core.PShape boundingBox(processing.core.PShape shape, double[] out) Computes the bounding box (envelope) of the givenPShapeand writes its coordinates to the provided array.The coordinates are written as:
{minX, minY, maxX, maxY}.- Parameters:
shape- the shape for which to calculate the bounding boxout- an array (length ≥ 4) that will hold the bounding box coordinates:- out[0] = minX
- out[1] = minY
- out[2] = maxX
- out[3] = maxY
- Returns:
- a
PShaperepresenting the bounding box of the input shape - Since:
- 2.1
-
convexHull
Computes the convex hull of a point set (the smallest convex polygon that contains all the points).- Parameters:
points- a collection of points- Returns:
- the minimum-area convex polygon containing the points
- Since:
- 1.3.0
-
convexHull
public static processing.core.PShape convexHull(processing.core.PShape shape) Computes the convex hull of the vertices from the input shape (the smallest convex polygon that contains all the shape's vertices).- Parameters:
shape- a concave shape- Returns:
- the minimum-area convex polygon containing the input's vertices
- Since:
- 1.3.0
-
concaveHull
public static processing.core.PShape concaveHull(processing.core.PShape shapeSet, double concavity, boolean tight) Constructs a concave hull of a set of polygons, respecting the polygons as constraints (i.e. the hull is guaranteed to contain the polygons).- Parameters:
shapeSet- a GROUP PShape, having multiple child PShapes, each of which is a polygonconcavity- a factor value between 0 and 1, specifying how concave the output is.tight- sets whether the boundary of the hull polygon is kept tight to precisely the outer edges of the input polygons- Returns:
- concave hull of the input shapes
- Since:
- 1.3.0
-
concaveHullDFS
public static processing.core.PShape concaveHullDFS(List<processing.core.PVector> points, double concavity) Computes the concave hull of a point set using a depth-first method. In contrast to the BFS method, the depth-first approach produces shapes that are more contiguous/less branching and spiral-like.- Parameters:
points-concavity- a factor value between 0 and 1, specifying how concave the output is (where 1 is maximal concavity)- Returns:
- Since:
- 1.1.0
- See Also:
-
concaveHullBFS
public static processing.core.PShape concaveHullBFS(List<processing.core.PVector> points, double edgeLengthRatio) Computes the concave hull of a point set using a breadth-first method.- Parameters:
points-edgeLengthRatio- Sets the target maximum edge length ratio for the concave hull. The edge length ratio is a fraction of the difference between the longest and shortest edge lengths in the Delaunay Triangulation of the input points. It is a value in the range 0.0 to 1; at 0.0 it produces a concave hull of minimum area that is still connected; 1.0 produces the convex hull.- Returns:
- Since:
- 1.1.0
- See Also:
-
concaveHullBFS2
public static processing.core.PShape concaveHullBFS2(List<processing.core.PVector> points, double threshold) Computes the concave hull of a point set using a different algorithm. This approach has a more "organic" structure compared to other concaveBFS method.- Parameters:
points-threshold- 0...1 (Normalized length parameter).- Setting
threshold=1means that no edges will be removed from the Delaunay triangulation, so the resulting polygon will be the convex hull. - Setting
threshold=0means that all edges that can be removed subject to the regularity constraint will be removed (however polygons that are eroded beyond the point where they provide a desirable characterization of the shape). - Although the optimal parameter value varies for
different shapes and point distributions, values between
0.05–0.2typically produce optimal or near-optimal shape characterization across a wide range of point distributions.
- Setting
- Returns:
- See Also:
-
snapHull
public static processing.core.PShape snapHull(processing.core.PShape shape, double convexity) Computes a hull, having a variable level of convexity, of a shape.When
convexity=0, the original shape is reproduced (a pure concave hull); the hull tends towards a convex hull of the input asconvexitygoes to1(in other words, a hull with some level of "snapping" to the original shape).- Parameters:
shape-convexity- how convex the snap hull is, where 0 is the original shape (no convexity, fully concave) and 1 forms the convex hull of the shape's vertices- Returns:
-