Skip to content

ComputeHull: exact QuickHull with coplanar face merging - #431

Open
joe-burns wants to merge 1 commit into
bepu:masterfrom
joe-burns:convex-hull-pr
Open

joe-burns wants to merge 1 commit into
bepu:masterfrom
joe-burns:convex-hull-pr

Conversation

@joe-burns

Copy link
Copy Markdown

So I was working on some mesh deformation with Compound ConvexHulls and noticed some lovely hulls were being generated, including some with some negative inertia (instantaneous 600k m/s is fun) and thought I'd take a look. With the help of our boy Claude I was able to implement the work you may have been avoiding. There is a new test with a 87 new point shapes to test all this and make sure it doesn't regress. I did not test it on the Windows harness, but the Mac harness I used (more details below) and a custom renderer showed significant improvements and a lack of "exploding hulls" as clud was so endearingly calling it. Anyways, this is weird to do a public PR for the first time, please advise.

Extended description from GIT commits and Claude summarization:

Point sets with many nearly coplanar points could come out of ComputeHull with an open or dented hull. Gift wrapping decides coplanarity within a tolerance, so a point near a face's plane could count as in front of one face and behind its neighbour. Of 87 point sets taken from pieces chopped off meshes (nearly coplanar points in clusters a fraction of a millimetre apart), gift wrapping left 74 open (the faces' area vectors off by up to 38 % of the area), one with a point 3.8 cm outside the hull, and 10 with face vertices off their planes. Shapes made from them got wrong volumes and inertias, in one case an inverse inertia that wasn't positive.

ComputeHull now builds hulls with volume using QuickHull, deciding whether a point is in front of a face with an exact orientation test: a double evaluation with Shewchuk's orient3d error bound, and when that can't decide, an exact evaluation with floating point expansions (error-free sums and products, the product via fused multiply-add), all on the stack. The hull is closed, convex and holds every point by construction. Near-coplanar points become vertices joined by sliver triangles, which are then merged into flat faces: adjacent triangles whose vertices lie within 1e-5 of the point set's size of a face's plane join it while its boundary stays a single loop. The result is written as HullData as before. Memory comes from the BufferPool; triangles keep their neighbours, outside points are a shared linked list.

Point sets with no volume (thinner than gift wrapping's own 1e-4 slab), and DEBUG_STEPS, still use gift wrapping, now ComputeHullGiftWrapping.

Tests (DemoTests/ConvexHullTests.cs): every point set must give a closed convex hull (area vectors cancel and the enclosed volume doesn't depend on the origin, allowing T-junctions; face vertices on their planes; every point inside), and a shape with a positive inertia whose bounding planes hold its points. The point sets (ConvexHullTests.PointSets.cs) are the 87 chopped sets and ConvexHullTestDemo's own; the demo's random cloud and hell cube (10, 50 and 200 wide) are generated. Flat sets must match gift wrapping and make no shape. The exact orientation was also checked against a BigInteger evaluation on a million near-degenerate cases, with no differences.

Timings (Release, Apple M1 Pro): the 87 chopped sets 2.4 ms a pass against gift wrapping's 3.8 ms; a 2048 point sphere 2.4 ms against 45 ms; 2048 points in a box 0.40 ms against 0.47 ms; a 240,000 point hell cube 165 ms. Point sets that are almost entirely exactly coplanar are slower (1536 points on a cube's faces, 0.35 ms against 0.07 ms), since most of their orientation tests need the exact evaluation.

Point sets with many nearly coplanar points could come out of ComputeHull
with an open or dented hull. Gift wrapping decides coplanarity within a
tolerance, so a point near a face's plane could count as in front of one face
and behind its neighbour. Of 87 point sets taken from pieces chopped off
meshes (nearly coplanar points in clusters a fraction of a millimetre apart),
gift wrapping left 74 open (the faces' area vectors off by up to 38 % of the
area), one with a point 3.8 cm outside the hull, and 10 with face vertices
off their planes. Shapes made from them got wrong volumes and inertias, in
one case an inverse inertia that wasn't positive.

ComputeHull now builds hulls with volume using QuickHull, deciding whether a
point is in front of a face with an exact orientation test: a double
evaluation with Shewchuk's orient3d error bound, and when that can't decide,
an exact evaluation with floating point expansions (error-free sums and
products, the product via fused multiply-add), all on the stack. The hull is
closed, convex and holds every point by construction. Near-coplanar points
become vertices joined by sliver triangles, which are then merged into flat
faces: adjacent triangles whose vertices lie within 1e-5 of the point set's
size of a face's plane join it while its boundary stays a single loop. The
result is written as HullData as before. Memory comes from the BufferPool;
triangles keep their neighbours, outside points are a shared linked list.

Point sets with no volume (thinner than gift wrapping's own 1e-4 slab), and
DEBUG_STEPS, still use gift wrapping, now ComputeHullGiftWrapping.

Tests (DemoTests/ConvexHullTests.cs): every point set must give a closed
convex hull (area vectors cancel and the enclosed volume doesn't depend on
the origin, allowing T-junctions; face vertices on their planes; every point
inside), and a shape with a positive inertia whose bounding planes hold its
points. The point sets (ConvexHullTests.PointSets.cs) are the 87 chopped sets
and ConvexHullTestDemo's own; the demo's random cloud and hell cube (10, 50
and 200 wide) are generated. Flat sets must match gift wrapping and make no
shape. The exact orientation was also checked against a BigInteger
evaluation on a million near-degenerate cases, with no differences.

Timings (Release, Apple M1 Pro): the 87 chopped sets 2.4 ms a pass against
gift wrapping's 3.8 ms; a 2048 point sphere 2.4 ms against 45 ms; 2048
points in a box 0.40 ms against 0.47 ms; a 240,000 point hell cube 165 ms.
Point sets that are almost entirely exactly coplanar are slower (1536 points
on a cube's faces, 0.35 ms against 0.07 ms), since most of their orientation
tests need the exact evaluation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant