The QuickHull library for Icy implements 2D and 3D algorithns to calculate convex envelopes from a given (random) set of points.
The 2D version of the algorithm is detailed here (see "alternative method"): https://en.wikipedia.org/wiki/Quickhull
The 3D version of the algorithm is detailed here: https://www.cs.ubc.ca/~lloyd/java/quickhull3d.html
The easiest way to use the library from within Icy is via the Convexify ROI plug-in
The low-level API can be accessed as follows:
- In 2D:
List<Point2D> points = ...
// replace the list by its envelope
points = QuickHull2D.computeConvexEnvelope(points);
// Conveniently, a region of interest is easy to create
ROI2DPolygon polygon = new ROI2DPolygon(points);
- In 3D:
Point3d points = ...
QuickHull3D qhull3d = new QuickHull3D();
// build the envelope (nothing is returned)
// The envelope is built as a mesh (faces and vertices), accessible via:
Point3d hullVertices = qhull3d.getVertices();
int faces = qhull3d.getVertices();
// However, conveniently, a ROI can easily be obtained from the QuickHull3D object using
ROI3DPolygonalMesh mesh = new ROI3DPolygonalMesh(qhull3d);