title: Algorithm To Find Minimum Distance Between Two Triangles
body: <p>This might be better asked on Math.SE, but I'll try here first:</p>
  
  <p>If I have two arbitrary triangles in 3D space, how can I determine the minimum distance between them? See the following: <a href="https://i.stack.imgur.com/1Q8Cw.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1Q8Cw.png" alt="enter image description here"></a> 
  It's difficult to see in the image, but triangle BAC is entirely in the positive Z-plane, whereas triangle DFE is entirely in the negative Z-plane. The normals for both triangles are parallel to the X-Y plane. The minimum distance between them is probably the distance between the two points I've plotted (H and G).</p>
  
  <p>Assuming the triangles are not co-planar, I know that one of the points representing the smallest distance between the two triangles must lie on either a vertex or along an edge for one of the triangles. For the other triangle, it can lie anywhere on the plane, including along the edges or vertices.</p>
  
  <p>I don't actually need the minimum distance itself - ultimately, all I need to find is whether or not the triangles are within some epsilon of each other.</p>
  
  <p>One thing I've tried is simply sampling the surfaces and applying a fast epsilon test to see if any points from one triangle are within epsilon of any points on the other, but this is too slow for my application. It seems to me that this should have a direct analytical solution, but I haven't been able to find anything about this problem at all.</p>