Example #1
0
        public static float DistanceBetweenPointAndLineSegment(ref FVector2 point, ref FVector2 lineEndPoint1,
                                                               ref FVector2 lineEndPoint2)
        {
            FVector2 v = FVector2.Subtract(lineEndPoint2, lineEndPoint1);
            FVector2 w = FVector2.Subtract(point, lineEndPoint1);

            float c1 = FVector2.Dot(w, v);

            if (c1 <= 0)
            {
                return(DistanceBetweenPointAndPoint(ref point, ref lineEndPoint1));
            }

            float c2 = FVector2.Dot(v, v);

            if (c2 <= c1)
            {
                return(DistanceBetweenPointAndPoint(ref point, ref lineEndPoint2));
            }

            float    b           = c1 / c2;
            FVector2 pointOnLine = FVector2.Add(lineEndPoint1, FVector2.Multiply(v, b));

            return(DistanceBetweenPointAndPoint(ref point, ref pointOnLine));
        }
Example #2
0
        public static float DistanceBetweenPointAndPoint(ref FVector2 point1, ref FVector2 point2)
        {
            FVector2 v;

            FVector2.Subtract(ref point1, ref point2, out v);
            return(v.Length());
        }