public static GetLinePlaneIntersection ( System.Vector3 &a, System.Vector3 &b, BEPUutilities.Plane &p, float &t, System.Vector3 &q ) : bool | ||
a | System.Vector3 | First endpoint of segment defining the line. |
b | System.Vector3 | Second endpoint of segment defining the line. |
p | BEPUutilities.Plane | Plane for comparison. |
t | float | Interval along line to intersection (A + t * AB). |
q | System.Vector3 | Intersection point. |
return | bool |
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;
}