Search code examples
c++intersectioncullingfrustum

Frustum and sphere intersection


I'm reading along this neat article here: Frustum Culling

and it reads that to find the distance between a sphere and a frustum side (a plane) is:

C = center of sphere

N = normal of plane

D = distance of plane along normal from origin

Distance = DotProduct(C, N) + D

But I don't understand what variable D refers to. Particularly, I don't understand what the origin of the frustum is. Is it where the camera eye would be?


Solution

  • D is the perpendicular distance you would need to travel along the normal of the plane to pass through the origin of whichever space the plane is defined in (I expect this to most often be the origin in world coordinates, but if your planes are described in camera coordinates then use the camera origin. Ultimately it doesn't matter as long as you are doing your calculations all in the same space. In other words, whichever origin you are using for the space that both the sphere and the planes are being compared in.).

    This is the same value in the plane equation: Ax + By + Cz + d = 0. d is the value D that you would be using. You can calculate d by taking a known point on the plane and using it to solve the plane equation for d. (A, B, C) are the X,Y,Z elements of your plane's unit normal vector, (x, y, z) are the coordinates of the point on the plane, solve the plane equation for d, and you have your distance.

    Just be mindful to do all of your calculations in the same space,,, be that world space or camera space or screen space. I suspect you'll want to do your calculations in world space.