-
Notifications
You must be signed in to change notification settings - Fork 17
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
quickhull3d does not always work if all points are on a same plane #30
Comments
Thanks for the bug report, a similar bug was opened a few years ago in #5 where the input only contains points in a plane, I remember I added this test: quickhull3d/test/index.test.js Lines 271 to 275 in 2012ad0
And verified that the output is a convex hull using: quickhull3d/test/index.test.js Lines 22 to 47 in 2012ad0
As you can see I'm using EPS of I understand the motivation of outputing 2 faces if the input only contains coplanar points, as you mention this is not a normal input case. A similar problem happens in a lower dimension, e.g. find a triangle with 3 co-linear points, effectively there's no triangle and we only have a line segment. If the input only contains coplanar points, we have a few options:
|
Given the example, is this a problem of determining the orientation of the point to the face? It looks like the first point has been assigned to another face. |
OK, no need for face to appear twice, that can be done by application using quickhull3d in postprocessing. The 5 points of the example from description are in order, so complete face would be [0,1,2,3,4].
So either Mauricio option (1) would be ok, reject input and let calling application deal with it (reposnse But not the current response Correct response: |
Sorry, that response is not correct. Perhaps correct response is
|
Thanks for the graph, for the case and the expected output, I think this library can do a better job for this scenario so I have an algorithm that I haven't implemented yet.
|
Thanks Mauricio. There is only one issue with your approach:
|
This should be fixed in the alpha release 3.1.0-1 https://www.npmjs.com/package/quickhull3d/v/3.1.0-1, let me know how it goes and I'll create a stable release 3.1.0. |
Hi,
|
|
I did git pull, created package.json for module as learned from @z3dev Does not take your changes:
|
Please let me know how I can undo whatever I did and test your current repo. |
|
Hi, This is above bug.js for the browser as bug.html:
And it correctly alerts now this:
Corresponding to this ASCII art diagram, similar to JSCAD screenshot above with bug output, but this time correct:
|
Thanks, I updated the output of the example in the README. |
@mauriciopoppe thanks a lot for the fix. And of course, this very nice library. |
Fix released in https://github.com/mauriciopoppe/quickhull3d/releases/tag/v3.1.0 |
I worked on JSCAd application lattice_sphere_cmp and made use of new geom3.fromPoints() which is based on quickhull3d. I realized that if all 3d points are on a same plane, the result might be wrong as in this bug.jscad simple JSCAD example:
I created JSCAD issue #1347, but was asked today to get quickhull3d fixed instead:
jscad/OpenJSCAD.org#1347 (comment)
Just using quickhull3d alone does show the bug as well (point 1 should appear in some faces, but does not):
jscad/OpenJSCAD.org#1347 (comment)
I already implemented fixes in the mentioned github issue — they are part of my lattice_sphere_cmp already. Basically a test is done whether all points are on a same plane. If not, normal quickhull3d is used. Otherwise a point known to be not on plane is added, then quickhull3d works nicely on the not all points on plane input, and finally all faces containing the added point are removed. Finally the result is the single face left, together with its inverse (to guarantee that face is visible from both sides). First animation shows what happens if only the remaining face is used in geom3, the second animation if both faces are used:
A good argument for having two faces in the result is looking at a tetrahedron where one edge is shortened until length 0:
The top and bottom face will remain.
The fix I have as discussed has to deal with non-integer distance of plane from origin, so comparison does not always work. I introduced a tolerance value for the functions that made it work, but I do not really like that.
For my lattice_sphere_cmp application all points are from ℤ³, and I used cross product instead of normalized normal vector to determine whether all points are on a same plane. That is clean, but all points in ℤ³ is not the normal use case for quickhull3d.
This is just issue report, no complete quickhull3d solution yet.
The code implemented can be found in these two diffs as well:
Hermann-SW/lattice_sphere_cmp@7834f9a#diff-93e00aa7bb721b3cc9d54a52895f396ada5a8dc0093c4c223ef9d7c39a1c145c
Hermann-SW/lattice_sphere_cmp@78225b5#diff-93e00aa7bb721b3cc9d54a52895f396ada5a8dc0093c4c223ef9d7c39a1c145c
The whole discussion on the algorithm is in this discord thread:
https://discord.com/channels/775984095250612234/1248251413629370389
Initial
fromPointsConvexPlaneℤ3(pts)
code is here:Hermann-SW/lattice_sphere_cmp@6461507#diff-93e00aa7bb721b3cc9d54a52895f396ada5a8dc0093c4c223ef9d7c39a1c145c
display="centroid!=normal +face" demonstrates the code discussed to display selected faces:
The text was updated successfully, but these errors were encountered: