How to find polygons in a given set of points and edges?

▼魔方 西西 提交于 2019-12-17 20:57:37

问题


Consider the following problem:

Given N points in plane and M line segments connecting them, find all polygons (convex or concave) that do not contain any other polygons inside.

For instance:

There are 5 polygons founded:

1 - 2 - 5 - 6

2 - 3 - 5

3 - 4 - 5

7 - 8 - 9

10 - 13 - 20 - 12 - 11

How can I identify these polygons and there corresponding vertices and edges? And what is the fastest solution for this?


回答1:


Build graph with segment ends as vertices and segments as edges, then find cycles using DFS.

Note that the same edges might belong to multiple cycles (polygons) like your 2-5 and there might be many variants to select cycles. To exclude ambiguity, you can build fundamental set of cycles

Edit. As weston noticed in comments, resulted polygons might contains others. So sketch of more geometric approach:

Build lists of adjacency for graph.
Sort edges in ever list by polar angle.
Choose the most bottom vertex A.
If it's degree is 0, remove vertex, if 1, remove vertex and edge.
Otherwise get edge E with the smallest angle from this vertex.

Walk to pair vertex B.
Choose the most left edge F from B.
Move along to F edge into C.
If dead end, remove F and vertex C and return to B.

Repeat moving using left-hand rule until meet vertex A or dead end vertex.
In the walk process remove edges outgoing from vertices of degree 2 or mark them as used.



来源:https://stackoverflow.com/questions/41245408/how-to-find-polygons-in-a-given-set-of-points-and-edges

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