在一个文章中看到一则运算代码:
求最小距离:其中a、b 是XY坐标系波形上两点,p是a-b 波形线上 移动的坐标点。
public static Point MiniDistance(Point a, Point b, Point p, out float min_distance) { Vector i = b - a; double t = DotProduct(i, p - a) / DotProduct(i, i); if (t < 0.0) { min_distance = (float)(p - a).Length; return a; } if (t > 1.0) { min_distance = (float)(p - b).Length; return b; } Point result = a + t * i; min_distance = (float)(p - result).Length; return result; }
private static double DotProduct(Vector m, Vector n) { return m.X * n.X + m.Y * n.Y; }
再于线成面的应用场景下,这个算出怎样的结果?
先记录,后理解
原文:https://www.cnblogs.com/ajdblog/p/14870858.html