Class ConvexHull2D
- java.lang.Object
-
- org.apache.commons.math3.geometry.euclidean.twod.hull.ConvexHull2D
-
- All Implemented Interfaces:
java.io.Serializable
,ConvexHull<Euclidean2D,Vector2D>
public class ConvexHull2D extends java.lang.Object implements ConvexHull<Euclidean2D,Vector2D>, java.io.Serializable
This class represents a convex hull in an two-dimensional euclidean space.- Since:
- 3.3
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private Segment[]
lineSegments
Line segments of the hull.private static long
serialVersionUID
Serializable UID.private double
tolerance
Tolerance threshold used during creation of the hull vertices.private Vector2D[]
vertices
Vertices of the hull.
-
Constructor Summary
Constructors Constructor Description ConvexHull2D(Vector2D[] vertices, double tolerance)
Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Region<Euclidean2D>
createRegion()
Returns a new region that is enclosed by the convex hull.Segment[]
getLineSegments()
Get the line segments of the convex hull, ordered.Vector2D[]
getVertices()
Get the vertices of the convex hull.private boolean
isConvex(Vector2D[] hullVertices)
Checks whether the given hull vertices form a convex hull.private Segment[]
retrieveLineSegments()
Retrieve the line segments from the cached array or create them if needed.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serializable UID.- See Also:
- Constant Field Values
-
vertices
private final Vector2D[] vertices
Vertices of the hull.
-
tolerance
private final double tolerance
Tolerance threshold used during creation of the hull vertices.
-
lineSegments
private transient Segment[] lineSegments
Line segments of the hull. The array is not serialized and will be created from the vertices on first access.
-
-
Constructor Detail
-
ConvexHull2D
public ConvexHull2D(Vector2D[] vertices, double tolerance) throws MathIllegalArgumentException
Simple constructor.- Parameters:
vertices
- the vertices of the convex hull, must be orderedtolerance
- tolerance below which points are considered identical- Throws:
MathIllegalArgumentException
- if the vertices do not form a convex hull
-
-
Method Detail
-
isConvex
private boolean isConvex(Vector2D[] hullVertices)
Checks whether the given hull vertices form a convex hull.- Parameters:
hullVertices
- the hull vertices- Returns:
true
if the vertices form a convex hull,false
otherwise
-
getVertices
public Vector2D[] getVertices()
Get the vertices of the convex hull.- Specified by:
getVertices
in interfaceConvexHull<Euclidean2D,Vector2D>
- Returns:
- vertices of the convex hull
-
getLineSegments
public Segment[] getLineSegments()
Get the line segments of the convex hull, ordered.- Returns:
- the line segments of the convex hull
-
retrieveLineSegments
private Segment[] retrieveLineSegments()
Retrieve the line segments from the cached array or create them if needed.- Returns:
- the array of line segments
-
createRegion
public Region<Euclidean2D> createRegion() throws InsufficientDataException
Returns a new region that is enclosed by the convex hull.- Specified by:
createRegion
in interfaceConvexHull<Euclidean2D,Vector2D>
- Returns:
- the region enclosed by the convex hull
- Throws:
InsufficientDataException
- if the number of vertices is not enough to build a region in the respective space
-
-