问题描述
我有两个多边形,我想获得最小距离,并测量该距离之间的点.当然,这一点很可能位于两个节点之间的边缘上.
I have two polygons and I want to get the minimal distance and the points between this distance is measured. Of course such a point could very well lie on the edge between two nodes.
这里是一个例子:
我正在寻找一种可以给我绿色距离和两点的算法.
I am looking for an algorithm that gives me the green distance and the two points.
推荐答案
如果多边形不相交,则可以执行以下操作:
If the polygons do not intersect, you could do this:
如果您有多边形A和多边形B,则A [i]和B [j]分别是A和B的顶点.然后,您可以计算从A [i]到B的每个分段的最近距离(您可以使用此,但要考虑到您要使用细分,因此必须使用细分的起点和终点.
If you have polygon A and polygon B and A[i] and B[j] are the vertexes of A and B respectively. Then you could compute the closest distance from A[i] to each segment of B (you could use something like this, but take into account that you'd be working with segments, so you have to work with the starting and ending point of the segment).
然后您必须执行相同的操作,但要从所有B [j]到A的所有段.
Then you have to do the same but from all B[j] to all segments of A.
最后拿最小的一个.
请记住我之前的评论:在计算到该段所在线的最短距离时,请考虑该段的起点和终点,因为相交点可能不在该段之内.在此处中查找检查这最后一件事.如果该点不在,则保持该线段的最近边缘)
Just remember my previous comment: consider the starting and ending point of the segment while computing the shortest distance to the line this segment is in, because the intersection point could be out of the segment. Look here to check this last thing. If the point is out keep the closest edge of the segment)
致谢
这篇关于两个多边形的最近点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!