首页 > 其他 > 详细

三维空间求最小距离应用场景的点滴疑问

时间:2021-06-10 15:11:32      阅读:19      评论:0      收藏:0      [点我收藏+]

在一个文章中看到一则运算代码:

求最小距离:其中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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!