3

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?

Community
  • 1
  • 1
sgtHale
  • 1,507
  • 1
  • 16
  • 28

1 Answers1

4

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.

YoungJohn
  • 946
  • 12
  • 18
  • 1
    Also note that "DotProduct(C, N) + D" is essentially the same thing as applying the plane equation (Ax + By + Cz + d) to the center of your sphere, a result of 0 means the center of the sphere lies exactly on the plane. – YoungJohn Aug 29 '14 at 19:17
  • So if it was defined in world coordinates and the frustum was at the origin, the origin which the normal would pass through is 0,0,0? – sgtHale Aug 29 '14 at 19:33
  • Yes, I believe that would be the origin you want. – YoungJohn Aug 29 '14 at 19:38