public static float PointClosest2Triangle3(Vector3 p1, Vector3 p2, Vector3 p3, ref Vector3 p, ref Vector3 close) { GeoPlane plane = new GeoPlane(p1, p2, p3); float d = GeoPlaneUtils.PointClosestToPlaneAbs(plane.mNormal, plane.mD, p, ref close); if (GeoTriangleUtils.IsPointInTriangle3(p1, p2, p3, ref close)) { return(d); } else { Vector3 close1 = new Vector3(); float dt = PointClosest2PlaneTriangle2(p1, p2, p3, plane, ref p, ref close1); return((float)Math.Sqrt(d * d + dt * dt)); } }