BEPUutilities.Toolbox.GetClosestPointOnSegmentToPoint C# (CSharp) Method

GetClosestPointOnSegmentToPoint() private method

private GetClosestPointOnSegmentToPoint ( List q, int i, int j, System.Vector3 &p, List subsimplex, List baryCoords, System.Vector3 &closestPoint ) : void
q List
i int
j int
p System.Vector3
subsimplex List
baryCoords List
closestPoint System.Vector3
return void
        public static void GetClosestPointOnSegmentToPoint(List<Vector3> q, int i, int j, ref Vector3 p, List<int> subsimplex, List<float> baryCoords, out Vector3 closestPoint)
        {
            Vector3 a = q[i];
            Vector3 b = q[j];
            subsimplex.Clear();
            baryCoords.Clear();
            Vector3 ab;
            Vector3.Subtract(ref b, ref a, out ab);
            Vector3 ap;
            Vector3.Subtract(ref p, ref a, out ap);
            float t;
            Vector3.Dot(ref ap, ref ab, out t);
            if (t <= 0)
            {
                subsimplex.Add(i);
                baryCoords.Add(1);
                closestPoint = a;
            }
            else
            {
                float denom = ab.X * ab.X + ab.Y * ab.Y + ab.Z * ab.Z;
                if (t >= denom)
                {
                    subsimplex.Add(j);
                    baryCoords.Add(1);
                    closestPoint = b;
                }
                else
                {
                    t = t / denom;
                    subsimplex.Add(i);
                    subsimplex.Add(j);
                    baryCoords.Add(1 - t);
                    baryCoords.Add(t);
                    Vector3 tab;
                    Vector3.Multiply(ref ab, t, out tab);
                    Vector3.Add(ref a, ref tab, out closestPoint);
                }
            }
        }

Same methods

Toolbox::GetClosestPointOnSegmentToPoint ( System.Vector3 &a, System.Vector3 &b, System.Vector3 &p, List subsimplex, System.Vector3 &closestPoint ) : void
Toolbox::GetClosestPointOnSegmentToPoint ( System.Vector3 &a, System.Vector3 &b, System.Vector3 &p, System.Vector3 &closestPoint ) : void