BEPUutilities.Toolbox.GetSquaredDistanceFromPointToLine C# (CSharp) Method

GetSquaredDistanceFromPointToLine() public static method

Determines the shortest squared distance from the point to the line.
public static GetSquaredDistanceFromPointToLine ( System.Vector3 &p, System.Vector3 &a, System.Vector3 &b ) : float
p System.Vector3 Point to check against the line.
a System.Vector3 First point on the line.
b System.Vector3 Second point on the line.
return float
        public static float GetSquaredDistanceFromPointToLine(ref Vector3 p, ref Vector3 a, ref Vector3 b)
        {
            Vector3 ap, ab;
            Vector3.Subtract(ref p, ref a, out ap);
            Vector3.Subtract(ref b, ref a, out ab);
            float e;
            Vector3.Dot(ref ap, ref ab, out e);
            return ap.LengthSquared() - e * e / ab.LengthSquared();
        }