Calculate segment of 3D line within distance from 3D triangle

26 Views Asked by At

Given an arbitrary 3D line (infinite length) and an arbitrary 3D triangle, how can I calculate which segment of the line (if any) is within a given distance d from the triangle?

Considerations:

  • Will the same method work whether the line intersects the triangle or not?
  • In the intersection case, what if it intersects along a line? (i.e. the line lies on the plane of the triangle)
  • If the calculation is expensive, are there any quick checks to see if there's a result at all? (i.e. skip the expensive part if it's "obvious" no part of the line is within the given distance)

I've tried imagining the line as a cylinder of radius d but that doesn't actually help me as I also don't know how to solve the problem of cylinder/triangle intersection. I've also thought about "flattening" the line into the triangle's plane to turn it into a 2D problem but I have a lot of trouble conceptualising its relation back to the 3D problem.