Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making hull builder more robust #735

Merged
merged 3 commits into from
Dec 25, 2022
Merged

Making hull builder more robust #735

merged 3 commits into from
Dec 25, 2022

Conversation

erincatto
Copy link
Owner

@erincatto erincatto commented Dec 14, 2022

Initially I tried to make gift wrapping handle collinear points better. Conclusion: gift wrapping is a bad algorithm.
So I removed gift wrapping and implemented quickhull. I also added code to explicitly remove collinear points. This turns out to be quite easy once you have a convex hull.

I ran over 200 million randomized tests successfully with test data that is very likely to have collinear points with small numerical deviations. All the tests passed and algorithm correctly rejects very close points and fully collinear points.

I also tested performance at around 150 milliseconds per million hulls.

I split out the convex hull code into a separate function b2ComputeHull. This lets people build hulls offline and check for hull validity before using them in b2PolygonShape.

This video is a good reference for the 2D quickhull algorithm (my implementation is different): https://www.youtube.com/watch?v=2EKIZrimeuk

Fixes: #671 #728

@erincatto erincatto merged commit d8e153b into main Dec 25, 2022
@erincatto erincatto deleted the erincatto/hull_fix branch December 25, 2022 01:28
brianwinterpixel pushed a commit to winterpixelgames/box2d that referenced this pull request Feb 16, 2023
nitially I tried to make gift wrapping handle collinear points better. Conclusion: gift wrapping is a bad algorithm.
So I removed gift wrapping and implemented quickhull. I also added code to explicitly remove collinear points. This turns out to be quite easy once you have a convex hull.

I ran over 200 million randomized tests successfully with test data that is very likely to have collinear points with small numerical deviations. All the tests passed and algorithm correctly rejects very close points and fully collinear points.

I also tested performance at around 150 milliseconds per million hulls.

I split out the convex hull code into a separate function b2ComputeHull. This lets people build hulls offline and check for hull validity before using them in b2PolygonShape.

This video is a good reference for the 2D quickhull algorithm (my implementation is different): https://www.youtube.com/watch?v=2EKIZrimeuk

Fixes: erincatto#671 erincatto#728
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.

No way to handle failed b2PolygonShape::Set
1 participant