I have a given infinite camera frustum defined by four planes, each defined by a normal (left, right, bottom, top). From those planes we can also easily get the camera position and the view direction. Further, I have an infinite cone specified by its apex, a direction vector, and the inner angle. I need to check whether those two intersect.
(Geogebra. The image and Geogebra playground use an infinite cone in both directions, but this question is about a cone only in one direction!)
There are some trivial special cases. The apex being inside the frustum, or the camera being inside the cone, are both easy to test for and result in the answer true
. Also, if the view direction and cone direction are sufficiently aligned, they will also necessarily intersect at some point, even if camera pos and apex are far apart. Else, if the apex is "behind" the camera (dot(apex - camera_pos, view_dir) < 0
) and if the cone points in a completely different direction (dot(view_dir, cone_dir) < 0
), then there is no intersection.
But I can't come up with a general solution. It's tricky because an intersection between both does not imply any of this:
- Any of the four plane-intersection-lines intersect the cone.
- The axis of the cone intersects the frustum.
- The cone and view dir pointing in roughly the same direction.
Simply checking whether the cone intersects any individual plane is also not sufficient as that would have many false positives.
I tried the approach of intersecting the cone with one plane first, finding the intersection point that's closest to ... something, such that I can simply test that intersection point against all other planes. But that hasn't lead anywhere yet.
I also got another idea: I think there are only three intersection cases: (a) cone axis intersects frustum, or (b) any frustum edge intersects the cone, or (c) the angle between cone axis and any frustum plane is smaller than the cone's inner angle. Is that correct?
I also appreciate useful approximations in answers!