As you can see the example picture below, my question is how to determine the polygons that are formed by series of point.
On the left picture, the series of point is {A, B, C, D, E, A}, so it just forms 1 polygon {A, B, C, D, E}.
On the right side of the picture, the series of point is {A, B, C, D, E, F, A}. It creates 2 polygons {A, F, G} and {B, C, D, E, G}, where G is intersect point from line AB and FE.
I am not only interested in the number of polygons, but i also want to know the polygon information (polygon's series of points) that are created from it.
This algorithms will be used in mobile device, in real time, so it must be fast enough to compute. Oh, and the series of points will be generated by user's drag touch points.
Assumptions:
I have been thinking the solution, and for looking the intersections points, I am stuck with the O(N^2) solution, N = number of edges. The optimization that I can do from this, is maintaining the sets of lines within some regions, so I just minimize the total lines that can be calculated each other.
As for the solution to extract what polygons are formed, I am still stuck.
First, find all points where segments cross and create new segments ending there, so that no segments cross any more (except for their ends). Then think of it as a graph, and remove each vertex of degree 1 until all such are gone.
Mark all sides of all segments as not visited. For each not visited side S
of segment (A, B)
walk A, B, C, ..., A
always taking the turn which is most on your S
side (angle sort minimum or maximum). You just found a polygon. This will give you one additional polygon, which is "all the rest on plane".
Overall complexity O(n^2).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With