Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygons from a list of edges

Given N points in a map of edges Map<Point, List<Edge>>, it's possible to get the polygons formed by these edges in O(N log N)?

What I know is that you have to walk all the vertices and get the edges containing that vertex as a starting point. These are edges of a voronoi diagram, and each vertex has, at most, 3 artists containing it. So, in the map, the key is a vertex, and the value is a list where the vertex is the start node.

For example:

Points: a,b,c,d,e,f,g

Edges: [a,b]; [a,c]; [a,d], [b,c], [d,e], [e,g], [g,f]

My idea is to iterate the map counterclockwise until I get the initial vertex. That is a polygon, then I put it in a list of polygons and keep looking for others. The problem is I do not want to overcome the complexity O(N log N)

Thanks!

like image 368
Valentina Ramirez Avatar asked Jan 12 '16 22:01

Valentina Ramirez


People also ask

Which polygon has 15 sides?

In geometry, a pentadecagon or pentakaidecagon or 15-gon is a fifteen-sided polygon.

How do you find the edges of a polygon?

For a polygon, we can say that an edge is a line segment on the boundary joining one vertex (corner point) to another. A Tetrahedron has 6 edges. For polyhedron shapes, a line segment where two faces meet is known as an edge.

What is a polygon with 13 sides?

A 13-sided polygon, sometimes also called the triskaidecagon.

What is a shape with 1000 sides called?

In geometry, a chiliagon (/ˈkɪliəɡɒn/) or 1000-gon is a polygon with 1,000 sides. Philosophers commonly refer to chiliagons to illustrate ideas about the nature and workings of thought, meaning, and mental representation.


2 Answers

You can loop through the edges and compute the distance from midpoint of the edge to all sites. Then sort the distances in ascending order and for inner voronoi polygons pick the first and the second. For outer polygons pick the first. Basically an edge separate/divide 2 polygons.

It's something O(m log n).

like image 190
Micromega Avatar answered Sep 20 '22 01:09

Micromega


If I did find a polynomial solution to this problem I would not post it here because I am fairly certain this is at least NP-Hard. I think your best bet is to do a DFS. You might find this link useful Finding all cycles in undirected graphs.

You might be able to use the below solution if you can formulate your graph as a directed graph. There are 2^E directed graphs (because each edge can be represented in 2 directions). You could pick a random directed graph and use the below solution to find all of the cycles in this graph. You could do this multiple times for different random directed graphs keeping track of all the cycles and until you've reached a satisfactory error bounds.

You can efficiently create a directed graph with a little bit of state (Maybe store a + or - with an edge to note the direction?) And once you do this in O(n) the first time you can randomly flip x << E directions to get a new graph in what will essentially be constant time.

Since you can create subsequent directed graphs in constant time you need to choose the number of times to run the cycle finding algorithm to have it still be polynomial and efficient.

UPDATE - The below only works for directed graphs

Off the top of my head it seems like it's a better idea to think of this as a graph problem. Your map of vertices to edges is a graph representation. Your problem reduces to finding all of the loops in the graph because each cycle will be a polygon. I think "Tarjan's strongly connected components algorithm" will be of use here as it can do this in O(v+e).

You can find more information on the algorithm here https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm

like image 41
CleoR Avatar answered Sep 21 '22 01:09

CleoR