java.lang.Object
imagingbook.common.geometry.hulls.ConvexHull
- All Implemented Interfaces:
ShapeProducer
This class calculate the convex hull of a 2D point set. It is based on the convex hull implementation provided by the
Apache Commons Math library, in particular classes ConvexHull2D
and MonotoneChain
[1]. See Sec. 8.4.2
of [2] for additional details.
[1]
https://commons.apache.org/proper/commons-math/index.html
[2] W. Burger, M.J. Burge, Digital Image
Processing – An Algorithmic Introduction, 3rd ed, Springer (2022).
- Version:
- 2022/06/24
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConvexHull
(Pnt2d[] points) Constructor, creates aAxisAlignedBoundingBox
instance from an array ofPnt2d
points.ConvexHull
(Iterable<Pnt2d> points) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface imagingbook.common.geometry.shape.ShapeProducer
getShape, getShapes, getShapes
-
Field Details
-
DefaultContainsTolerance
- See Also:
-
-
Constructor Details
-
ConvexHull
Constructor, creates aConvexHull
instance from anIterable
overPnt2d
. At least one distinct point is required.- Parameters:
points
- an iterator over 2D points
-
ConvexHull
Constructor, creates aAxisAlignedBoundingBox
instance from an array ofPnt2d
points. At least one distinct point is required.- Parameters:
points
- an array of 2D points
-
-
Method Details
-
getVertices
Returns a sequence of 2D points on the convex hull (in counter-clockwise order).- Returns:
- sequence of 2D points on the convex hull
-
getShape
Description copied from interface:ShapeProducer
Returns a scaledShape
for this object (default scale is 1). Must be defined by implementing classes. The interpretation of the scale factor is left to the implementing class. For example, forPnt2d
it specifies the size of the marker (seePnt2d.getShape(double)
.- Specified by:
getShape
in interfaceShapeProducer
- Parameters:
scale
- the scale of the shape- Returns:
- a
Shape
instance
-
contains
-
contains
Checks if this convex hull contains the specified point. This method is used instead ofPath2D.contains(double, double)
to avoid false results due to roundoff errors.- Parameters:
p
- some 2D pointtolerance
- positive quantity for being outside- Returns:
- true if the point is inside the hull
-