internal static double PointToSegment(XVertex A, XVertex B, XVertex C) { double dot1 = Dot3Product(A, B, C); if (dot1 > 0) { return(B.Distance(C)); } double dot2 = Dot3Product(B, A, C); if (dot2 > 0) { return(A.Distance(C)); } double dist = Cross3Product(A, B, C) / A.Distance(B); return(Math.Abs(dist)); }