How to determine whether a line segment intersects a frustum?

I need to be able to determine whether the straight line between two points (segment), crosses the space inside a frustum (intersects the frustum). I’ve looked into the APIs offered by THREE.js and haven’t been able to find it.

What I’ve tried

  • use containsPoint api for the two points of the line. Obviously not good enough, as this requires the entire segment to be contained in the frustum
  • use intersectsBox, with a 1 dimensional box which mimics a segment. The limitation is that Box3 is axis-aligned by default and it would only work with axis-aligned segments.

You could run through the 6 planes and check if the segment intersects. If it has 0 intersections it doesn’t intersect, with 1 intersection it stops inside the frustum, with 2 it goes through.

1 Like

That’s very helpful, thank you!

I think the last part about 2 planes, is only true of the two planes are neighbours. if the line goes through two planes which are facing each other, the line doesn’t necessarily go through the frustum, correct?

If the segment is long enough it would pass through the opposite face as well since frustums are closed polygons.

Since the threejs plane extends infinitely in space, I don’t think this will work? A line can cross two infinite planes and still be outside the frustum

I think I figured it out. We can use the method intersectLine from Plane to find out whether a line intersects with a plane and if yes, at which point. once we have the point, we can check if that point is inside the frustum using containsPoint method.

2 Likes