栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何从多边形内的点获取多边形外的最近点?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何从多边形内的点获取多边形外的最近点?

要知道该点在哪个多边形中,可以使用“ 射线投射”算法。

为了找到最接近的边缘,您可以使用幼稚的方法来计算到每个边缘的距离,然后取最小值。只要记住检查与边的交点是否在边之外(请检查此)。如果在外面,则将其距离边缘的最近端点。

可以用一些伪代码更好地解释直觉:

dot(u,v) --> ((u).x * (v).x + (u).y * (v).y)norm(v)  --> sqrt(dot(v,v))     // norm = length of vectordist(u,v)--> norm(u-v)          // distance = norm of difference// Vector contains x and y// Point contains x and y// Segment contains P0 and P1 of type Point// Point  = Point ± Vector// Vector = Point - Point// Vector = Scalar * VectorPoint closest_Point_in_Segment_to(Point P, Segment S){     Vector v = S.P1 - S.P0;     Vector w = P - S.P0;     double c1 = dot(w,v);     if ( c1 <= 0 )   // the closest point is outside the segment and nearer to P0          return S.P0;     double c2 = dot(v,v);     if ( c2 <= c1 )  // the closest point is outside the segment and nearer to P1          return S.P1;     double b = c1 / c2;     Point Pb = S.P0 + b * v;     return Pb;}[Point, Segment] get_closest_border_point_to(Point point, Polygon poly) {    double bestDistance = MAX_DOUBLE;    Segment bestSegment;    Point bestPoint;    foreach s in poly.segments {        Point closestInS = closest_Point_in_Segment_to(point, s);        double d = dist(point, closestInS);        if (d < bestDistance) { bestDistance = d; bestSegment = s; bestPoint = closestInS;         }    }    return [bestPoint, bestSegment];}

我认为这个伪代码应该可以帮助您,当然,一旦有了要插入的多边形!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/650057.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号