public static double DistancePointLine3D(clsPoint3d p1, clsLine3d l1) { //Distance between 3D point and truncated 3D line clsPoint3d p3d = new clsPoint3d(); double l = 0; p3d = ProjectPoint(p1, l1); l = l1.Lambda(p3d); if (l < 0) { return(p1.Dist(l1.P1)); } if (l > 1) { return(p1.Dist(l1.P2)); } return(p1.Dist(p3d)); }