What is the quickest way to find the shortest cartesian distance between two polygons

后端 未结 13 1819
迷失自我
迷失自我 2021-02-01 05:54

I have 1 red polygon say and 50 randomly placed blue polygons - they are situated in geographical 2D space. What is the quick

13条回答
  •  别跟我提以往
    2021-02-01 06:24

    I would start by bounding all the polygons by a bounding circle and then finding an upper bound of the minimal distance. Then i would simply check the edges of all blue polygons whose lower bound of distance is lower than the upper bound of minimal distance against all the edges of the red polygon.

    upper bound of min distance = min {distance(red's center, current blue's center) + current blue's radius}
    
    for every blue polygon where distance(red's center, current blue's center) - current blue's radius < upper bound of min distance
        check distance of edges and vertices
    
    

    But it all depends on your data. If the blue polygons are relatively small compared to the distances between them and the red polygon, then this approach should work nicely, but if they are very close, you won't save anything (many of them will be close enough). And another thing -- If these polygons don't have many vertices (like if most of them were triangles), then it might be almost as fast to just check each red edge against each blue edge.

    hope it helps

提交回复
热议问题