I’m looking through MG math related stuff (planes, frustum and everything in between) and came across this method under PlaneHelper, that is used internally when calculating intersection between frustum and bounding box:
public static float PerpendicularDistance(ref Vector3 point, ref Plane plane)
{
return (float)Math.Abs((double)(plane.Normal.X * point.X + plane.Normal.Y * point.Y + plane.Normal.Z * point.Z) / Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z));
}
I’m curious about this part:
Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z))
Seems like MG calculates the plane normal length and divide by it. While its not that bad in terms of performance, its also not that cheap either, and afaik Plane normal should always have length of 1.
Am I missing something here regarding frustum planes and reasons why it may not be normalized? Or is this code just-in-case someone feed the method a plane with a Normal that is not… normal?
Thanks!