public static bool TryRayPlane(
Vector3D rayOrigin,
Vector3D rayDirection,
Vector3D planeNormal,
double planeD,
out Vector3D intersectionPoint)
{
double denominator = planeNormal.Dot(rayDirection);
if (Math.Abs(denominator) < 0.00000000000000000001)
{
//
// Ray is parallel to plane. The ray may be in the polygon's plane.
//
intersectionPoint = Vector3D.Zero;
return false;
}
double t = (-planeD - planeNormal.Dot(rayOrigin)) / denominator;
if (t < 0)
{
intersectionPoint = Vector3D.Zero;
return false;
}
intersectionPoint = rayOrigin + (t * rayDirection);
return true;
}