标签:
1 public static double PointToSegDist(double x, double y, double x1, double y1, double x2, double y2) 2 { 3 double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1); 4 if (cross <= 0) return Math.Sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); 5 6 double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); 7 if (cross >= d2) return Math.Sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2)); 8 9 double r = cross / d2; 10 double px = x1 + (x2 - x1) * r; 11 double py = y1 + (y2 - y1) * r; 12 return Math.Sqrt((x - px) * (x - px) + (py - y1) * (py - y1)); 13 }
来自:http://blog.csdn.net/angelazy/article/details/38489293/
标签:
原文地址:http://www.cnblogs.com/yuanbo123/p/5448888.html