Sign in to follow this  
Psyk60

Distance to arbitrary mesh

Recommended Posts

I want a way to find the distance between an arbitrary point in 3D space and the closest point on the surface of an arbitrary triangle mesh. So I guess it boils down to finding the closest point on the mesh. Can anyone point me in the right direction? I'm not too bothered about it being efficient, I only need it to illustrate a point.

Share this post


Link to post
Share on other sites
closest point on triangle x many triangle, take the closest :)

http://www.gamedev.net/community/forums/topic.asp?topic_id=516608

Share this post


Link to post
Share on other sites
This is similar to collision detection. First find the normal from the given point to the plane of a triangle. If that normal intersects the plane inside the borders of the triangle you are done for that triangle. Otherwise find the normals from the point to each of the three lines containing the edges. If a normal intersect its respectve line within the bounds of its edge you are done for that edge and you do not have to check its end points (however you still need to check the other two edges and the other point in the triangle for a closer intersection) . If you still haven't found any intersections, just take the closest point of the three.

Note, you have to apply this to all the triangles in the mesh but there are some optimizations. For instance if you check for an edge intersection you don't have to check it again from the adjoining triangle. What you might do is check all faces first, then check all edges and check all points, setting flags for objects I don't need to check as I go along. For instance, if you find a face intersection you can set flags on all its edges and points so you don't check them again. Or if you find an edge intersection you can just set flags on its points.

You can also use bounding spheres to sort your triangles before starting any tests. That way you can eliminate most of your checks. If you do this you will probably want to check one complete triangle at a time as opposed to doing face then edge and then point checks although you can still make use of the flags. You can also eliminate faces that face away from the target point as well as their edges and points, assuming you don't care if this works from inside your mesh.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this