Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
914 views
in Technique[技术] by (71.8m points)

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

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: Example

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...