-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Added functions to get distances to primatives and meshes #148
base: master
Are you sure you want to change the base?
Conversation
Created new file distances.jl which computes the absolute_distance and the signed_distance to triangle meshes, HyperSpheres and HyperRects. These functions have been exported. The sphere and rect signed functions are straightforward, and there is a fallback for absolute_distance to equal abs(signed_distance). Dealing with triangles and triangle meshes is less straightforward. The absolute distance to a triangle is a well defined (if complex) function, but the signed distance isn't. I've used the signed distance to the plane aligned with the triangle. The signed distance to a mesh of triangles is then the signed distance to the convex union of those planes. This is simple, but obviously has drawbacks. Alternatively, the absolute distance to a mesh of triangles is robust, and could be supplimented with a global operation (like the winding number) to determine a sign. I've added a 27 tests to runtests which illustrate some of these issues.
For reference I have a few more of these functions here: https://github.com/sjkelly/Descartes.jl/blob/master/src/frep.jl |
That's great. Do you think it makes sense to merge some of them? |
Yes, feel free copy whatever is useful from Descartes, assuming people are on board with adding these distance functions. |
Thank you :) |
So the three primitives I haven't covered yet are It looks like A |
|
||
Return the minimum absolute distance from point `p` to any Triangle in `mesh`. | ||
""" | ||
absolute_distance(p,mesh::AbstractMesh) = minimum(t->absolute_distance(p,t), nonzero(mesh)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to scale poorly on performance, so I'm not sure if this will give the right experience. IIUC for Mesh->SDF you normally want to bin faces in an octree, kd tree, or other, to try to reduce the search space first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very true. This is where some help from people more familiar with these kind of approaches would be great.
I'm on the fence about distances for |
By uniform sampling, do you mean filling an entire array with the SDF of a mesh? Because that is my use case. In fact, I only need this to be accurate fairly close to the mesh, so my plan was to loop through all the mesh faces and fill the array points in the face's bounding box. So this would scale with the number of faces times number of array points per face. For the general case, I agree that you need some kind of tree method, but this requires some data-structures be set up within GeometryBasics. You could also apply a tree to the array, such as a multi-grid search. |
Nice! This would be useful to a few other packages, as-is so I am for it. |
Hold the phone. Looking at |
But |
It's usually not too hard to upgrade to GeometryBasics, since most APIs have stayed fairly similar! |
What is the process/etiquette for this? I've raised an issue on |
Good question... I think those may not be maintained anymore... We can ask, if they want to move the package to JuliaGeometry, so it can be maintained by more people! |
FWIW the GT->GB transition is a pretty big ask. A huge amount of their stack is in GeometryTypes, with EnhancedGJK being pretty key foundation. One approach would be to use |
Created new file distances.jl which computes the absolute_distance and
the signed_distance to triangle meshes, HyperSpheres and HyperRects.
These functions have been exported.
The sphere and rect signed functions are straightforward, and there is a
fallback for absolute_distance to equal abs(signed_distance).
Dealing with triangles and triangle meshes is less straightforward. The
absolute distance to a triangle is a well defined (if complex) function,
but the signed distance isn't. I've used the signed distance to the
plane aligned with the triangle. The signed distance to a mesh of
triangles is then the signed distance to the convex union of those
planes. This is simple, but obviously has drawbacks.
Alternatively, the absolute distance to a mesh of triangles is robust,
and could be supplimented with a global operation (like the winding
number) to determine a sign.
I've added a 27 tests to runtests which illustrate some of these issues.