打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
求点在线上的投影点
public enum PointPositonType
        {
            OutOfStartPoint,
            InTheLine,
            OutOfEndPoint
        }

        public static PointPositonType GetNearestPoint(Point startPoint, Point endPoint, Point outPoint, out Point nearestPoint)
        {
            nearestPoint = new Point();

            if (Math.Abs(endPoint.Y - startPoint.Y) < 1e-6)  //斜率为0的处理
            {
                nearestPoint.X = outPoint.X;
                nearestPoint.Y = startPoint.Y;
            }
            else                                           //垂直向量斜率之积为-1
            {
                double dIntercept1 = (endPoint.Y - startPoint.Y) / (endPoint.X - startPoint.X);

                double dIntercept2 = -1.0 / dIntercept1;

                nearestPoint.X = (dIntercept1 * startPoint.X - dIntercept2 * outPoint.X + outPoint.Y - startPoint.Y) / (dIntercept1 - dIntercept2);

                nearestPoint.Y = dIntercept1 * (nearestPoint.X - startPoint.X) + startPoint.Y;
            }

            Vector ab = endPoint - startPoint;
            Vector ac = outPoint - startPoint;

            //c在ab线段左侧延长线上,c与ab线段所成的角为钝角
            double f = ab * ac;

            if (f < 0) 
            {
                return PointPositonType.OutOfStartPoint;
            }

            //c在ab线段的右侧延长线上,c与ab线段所成的角为锐角
            double d = ab * ab;
            if (f > d)   
            {
                return PointPositonType.OutOfEndPoint;
            }

            // c在ab线段上的投影点

            return PointPositonType.InTheLine;
        }

推导公式 为:

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WPF 颜色渐变
抛物线算法(已知起点、终点、高度)
在iOS中使用手指简单画线
WPF Slider 样式
VBA和VB应用程序之异同和相互移植
VBA实现Excel与CAD表格互转
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服