Closest points of two polygons

依然范特西╮ 提交于 2019-12-07 06:11:59

问题


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.

Here is an example:

I am looking for an algorithm that gives me the green distance and the two points.


回答1:


If the polygons do not intersect, you could do this:

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).

Then you have to do the same but from all B[j] to all segments of A.

And finally take the smallest one.

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)

Regards



来源:https://stackoverflow.com/questions/18973808/closest-points-of-two-polygons

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!