Basic Distance questions

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.

  • Dom

Correction - On second thoughts, this won’t do at all :frowning: 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):

http://xengine.sourceforge.net/docs/structXEngine_1_1Math_1_1DistanceAlgorithms_1_1DistancePointToTriangle.html

Hope this helps

God help me… thanks.