public static bool GetLinePlaneIntersection(ref Vector3 a, ref Vector3 b, ref Plane p, out float t, out Vector3 q)
{
Vector3 ab;
Vector3.Subtract(ref b, ref a, out ab);
float denominator;
Vector3.Dot(ref p.Normal, ref ab, out denominator);
if (denominator < Epsilon && denominator > -Epsilon)
{
//Surface of plane and line are parallel (or very close to it).
q = new Vector3();
t = float.MaxValue;
return false;
}
float numerator;
Vector3.Dot(ref p.Normal, ref a, out numerator);
t = (p.D - numerator) / denominator;
//Compute the intersection position.
Vector3.Multiply(ref ab, t, out q);
Vector3.Add(ref a, ref q, out q);
return true;
}