Closest Points on Two Triangles in 3D Space

147 Views Asked by At

I have two triangles in 3D space, defined by 3 (x, y, z) points each. I'm looking to find the closest points between the two triangles, whether that be on surface, edge, or point.

I'm unsure how to go about this, the Geometric Tools site has a function for this, but I'm not entirely sure how it's working and having a bit of trouble trying to decode it (I'd like to understand what the algorithm is doing rather than just copying it). That solution can be found at:

http://www.geometrictools.com/LibMathematics/Distance/Distance.html

Any help or suggestions would be greatly appreciated.

I imagine there are several cases to take into account here, comparing edges to edges on the other triangles, comparing points to edges (although I suppose that might come under edges to edges), and determining whether the point is on the actual surface of the triangle, within the bounds.

The latter will be the difficult one, and is where I'm having trouble (telling when and actually finding the point).

Thanks.