BEPUphysics.CollisionTests.CollisionAlgorithms.GJK.SimpleSimplex.GetPointOnSegmentClosestToOrigin C# (CSharp) Method

GetPointOnSegmentClosestToOrigin() public method

Gets the closest point on the segment to the origin.
public GetPointOnSegmentClosestToOrigin ( Microsoft.Xna.Framework.Vector3 &point ) : void
point Microsoft.Xna.Framework.Vector3 Closest point.
return void
        public void GetPointOnSegmentClosestToOrigin(out Vector3 point)
        {
            Vector3 segmentDisplacement;
            Vector3.Subtract(ref B, ref A, out segmentDisplacement);
            float dotA;
            Vector3.Dot(ref segmentDisplacement, ref A, out dotA);

            //Inside segment.
            float V = -dotA / segmentDisplacement.LengthSquared();

            Vector3.Multiply(ref segmentDisplacement, V, out point);
            Vector3.Add(ref point, ref A, out point);

            //if (dotB > 0)
            //{
            //}
            //else
            //{
            //    //It is not possible to be anywhere but within the segment in a 'boolean' GJK, where it early outs as soon as a separating axis is found.

            //    //Outside B.
            //    //Remove current A; we're becoming a point.
            //    A = B;
            //    State = SimplexState.Point;

            //    point = A;
            //}
            //It can never be outside A! 
            //That would mean that the origin is LESS extreme along the search direction than our extreme point--- our search direction would not have picked that direction.
        }