- Home /
Check if a vector is close to a mesh
Hello! I'd like to know what the fastest way to detect if a vector is relatively close to a mesh intersection. Using rays would be far too expensive for what I'm doing. I was trying to find a way to go through each vertex and check the vertices it's connected to (Which I did successfully) and then check if the vector is close to intersecting a triangle between them (Which I did not do successfully)
Any help is appreciated. Thanks!
Trying to see how close a 3D point in world space is to touching a mesh.
Answer by robertbu · Feb 03, 2013 at 04:38 PM
This is an interesting problem, so I poked around a bit. There is a variety of both math and code for finding the distance between a point and a triangle on the net. Here are two links to code (will have to be translated):
I also found an interesting algorithm by DarrenW at the bottom of this page:
Determine if a 3D point is within a triangle
It was interesting for two reasons. First it may give you a way of determining nearness without actually calculating the distance. Second, it may give you the tools to determine which side of the triangle the points is on (I'm slow with this kind of math and would have to plod out an answer to the 'mays'...perhaps someone else on the list with a stronger math background can comment). I'm not sure why you are doing the calculations, but if you are calculating nearness to a closed object, determining if the point is inside the object may be important.
I also bumped into this page on the Unity Community Wiki:
It doesn't directly solve your problem, but it does have solutions that there were building block to some of the algorithms on the net.
If you are going to do this a lot (same mesh different points), it will likely make sense to preprocess the mesh and build some data structures for faster searching. Good Luck.
Wow, thanks!
I never get answers like this.
If it makes you guys happy, I'm attempting to make a real-time GI implementation for Unity, and perhaps even Unity Free, to be released publicly. I have no promises that I will be able to get it done, as I am decently slow myself, and may not know how to code some of the functions to be optimized for modern PC's. But, if I can, I will be sure to release it.
Your answer
Follow this Question
Related Questions
mesh into smaller triangles 0 Answers
Accessing Mesh: Triangle and Vertex array fields directly? 0 Answers
Want to create a new mesh (single triangle) "cloned" from an already existing triangle .... 2 Answers
Making Different vertices,triangle,uv maps in the same mesh 1 Answer
65,000 vertices or 65,000 triangles? Disambiguation please. 2 Answers