Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decomposition to Convex Polygons

Tags:

geometry

This question is a little involved. I wrote an algorithm for breaking up a simple polygon into convex subpolygons, but now I'm having trouble proving that it's not optimal (i.e. minimal number of convex polygons using Steiner points (added vertices)). My prof is adamant that it can't be done with a greedy algorithm such as this one, but I can't think of a counterexample.

So, if anyone can prove my algorithm is suboptimal (or optimal), I would appreciate it.

The easiest way to explain my algorithm with pictures (these are from an older suboptimal version)

What my algorithm does, is extends the line segments around the point i across until it hits a point on the opposite edge.

If there is no vertex within this range, it creates a new one (the red point) and connects to that:

If there is one or more vertices in the range, it connects to the closest one. This usually produces a decomposition with the fewest number of convex polygons:

However, in some cases it can fail -- in the following figure, if it happens to connect the middle green line first, this will create an extra unneeded polygon. To this I propose double checking all the edges (diagonals) we've added, and check that they are all still necessary. If not, remove it:

In some cases, however, this is not enough. See this figure:

Replacing a-b and c-d with a-c would yield a better solution. In this scenario though, there's no edges to remove so this poses a problem. In this case I suggest an order of preference: when deciding which vertex to connect a reflex vertex to, it should choose the vertex with the highest priority:

lowest) closest vertex

med) closest reflex vertex

highest) closest reflex that is also in range when working backwards (hard to explain) --

In this figure, we can see that the reflex vertex 9 chose to connect to 12 (because it was closest), when it would have been better to connect to 5. Both vertices 5 and 12 are in the range as defined by the extended line segments 10-9 and 8-9, but vertex 5 should be given preference because 9 is within the range given by 4-5 and 6-5, but NOT in the range given by 13-12 and 11-12. i.e., the edge 9-12 elimates the reflex vertex at 9, but does NOT eliminate the reflex vertex at 12, but it CAN eliminate the reflex vertex at 5, so 5 should be given preference.

It is possible that the edge 5-12 will still exist with this modified version, but it can be removed during post-processing.

Are there any cases I've missed?


Pseudo-code (requested by John Feminella) -- this is missing the bits under Figures 3 and 5

assume vertices in `poly` are given in CCW order
let 'good reflex' (better term??) mean that if poly[i] is being compared with poly[j], then poly[i] is in the range given by the rays poly[j-1], poly[j] and poly[j+1], poly[j]

for each vertex poly[i]
    if poly[i] is reflex
        find the closest point of intersection given by the ray starting at poly[i-1] and extending in the direction of poly[i] (call this lower bound)
        repeat for the ray given by poly[i+1], poly[i] (call this upper bound)

        if there are no vertices along boundary of the polygon in the range given by the upper and lower bounds
            create a new vertex exactly half way between the lower and upper bound points (lower and upper will lie on the same edge)
            connect poly[i] to this new point
        else
            iterate along the vertices in the range given by the lower and upper bounds, for each vertex poly[j]
                if poly[j] is a 'good reflex'
                    if no other good reflexes have been found
                        save it (overwrite any other vertex found)
                    else
                        if it is closer then the other good reflexes vertices, save it
                else
                    if no good reflexes have been found and it is closer than the other vertices found, save it
            connect poly[i] to the best candidate
        repeat entire algorithm for both halves of the polygon that was just split
// no reflex vertices found, then `poly` is convex
save poly

Turns out there is one more case I didn't anticipate: [Figure 5]

My algorithm will attempt to connect vertex 1 to 4, unless I add another check to make sure it can. So I propose stuffing everything "in the range" onto a priority queue using the priority scheme I mentioned above, then take the highest priority one, check if it can connect, if not, pop it off and use the next. I think this makes my algorithm O(r n log n) if I optimize it right.


I've put together a website that loosely describes my findings. I tend to move stuff around, so get it while it's hot.

like image 918
mpen Avatar asked Mar 29 '09 04:03

mpen


People also ask

How do you make a polygon convex?

Sum of all the interior angles of a polygon of n sides = (n – 2)180°. The diagonals of the convex polygon lie completely inside the polygon. Area of convex polygon can be determined by dividing the polygon into triangles and then finding the area of each triangle and summing up them.

What is convex polygon theorem?

The Convex Polygon Theorem states that the optimum (maximum or minimum) solution of a LLP is attained at least one of the corner points of the convex set over which the solution is feasible.

Can a concave polygon be convex?

A concave polygon is a polygon which is not convex. This polygon is just the opposite of a convex polygon. A simple polygon is considered as a concave polygon if and only if at least one of the interior angles is a reflex angle (between 180° and 360°).


1 Answers

I believe the regular five pointed star (e.g. with alternating points having collinear segments) is the counterexample you seek.

Edit in response to comments

In light of my revised understanding, a revised answer: try an acute five pointed star (e.g. one with arms sufficiently narrow that only the three points comprising the arm opposite the reflex point you are working on are within the range considered "good reflex points"). At least working through it on paper it appears to give more than the optimal. However, a final reading of your code has me wondering: what do you mean by "closest" (i.e. closest to what)?

Note

Even though my answer was accepted, it isn't the counter example we initially thought. As @Mark points out in the comments, it goes from four to five at exactly the same time as the optimal does.

Flip-flop, flip flop

On further reflection, I think I was right after all. The optimal bound of four can be retained in a acute star by simply assuring that one pair of arms have collinear edges. But the algorithm finds five, even with the patch up.

I get this:

removing dead ImageShack link

When the optimal is this:

removing dead ImageShack link

like image 71
MarkusQ Avatar answered Nov 11 '22 22:11

MarkusQ