Closest point on ray to triangle in 3D

584 Views Asked by At

There's a great many articles on finding the intersecting of a ray and a triangle, or the closest point on a triangle to some other point. However, I can't find anything for finding the closest points between a ray and a triangle.

Perhaps a bit more formally, given the triangle defined by points A, B, and C, and a ray defined by an origin O and a direction D, find the two points P and Q where P is on the ray, Q is on the triangle, and the distance between P and Q is minimal.

I've tried to start with editing a ray-triangle intersection algorithm, but I don't think that's going to work. A lot of them seem to find where the ray intersects with the plane defined by the triangle, but that's not necessarily the closest point (imagine a ray that is mostly parallel to the plane and slightly above it - the closest point on the ray would be above the triangle, not intersecting its plane).

Has anyone developed an algorithm for this, and if so, what is it?

1

There are 1 best solutions below

1
On

Putting together some stuff from this question's comments:

  • First do a regular ray-triangle intersection test. If it passes, the closest point is obviously the intersection.
  • If the ray is facing away from the triangle (i.e. the ray's time-of-intersection with the plane defined by the triangle is negative, which most ray-triangle intersections test for), the closest point on the ray is the ray's origin. Can use that point with a standard algorithm to find the corresponding closest point on the triangle.
  • Otherwise, the closest point will be on one of the triangle's edges. Run the closest point on ray and line segment algorithm on all 3 of the edges and take the one that's closest.

(For lines parallel to the triangle, there may not be a singular closest point, but that does not matter for my case in particular)