I am having trouble finding a couple equations.
The distance between a point and a triangle (defined by three points) and the distance between a ray and a triangle. I know, I know, I should know this, but I don’t and I google is letting me down.
I am having trouble finding a couple equations.
The distance between a point and a triangle (defined by three points) and the distance between a ray and a triangle. I know, I know, I should know this, but I don’t and I google is letting me down.
Distance between point § and tri is easy…
Take the face normal of the tri ( verts v1,v2,v3):
myVector n = (v2-v1).crossProduct( v3 - v1 );
n.normalize();
Then just take tha absolute dot product this with the vector from any tri point to the point in question:
float dist = fabs( n.dotProduct( P - v1 ) );
Distance from a line to a tri is much more complicated, I would google for effecient algorithms for it.
Correction - On second thoughts, this won’t do at all
This just gives the distance from a plane. Sry… Ill look up the distance from a tri instead…
Ok… Its really not nice.
Heres a link to the theory:
http://www-compsci.swan.ac.uk/~csmark/PDFS/dist.pdf
Heres a link to some source that does it (not java):
Hope this helps
God help me… thanks.