polygon union without holes

You can proceed as below:

First, add to your set of points all the points of intersection of your polygons.

Then I would proceed like graham scan algorithm but with one more constraint.

Instead of selecting the point that makes the highest angle with the previous line (have a look at graham scan to see what I mean (*), chose the one with the highest angle that was part of one of the previous polygon.

You will get an envellope (not convex) that will describe your shape.


It's similar to finding the convex hull of your points.

For example graham scan algorithm will help you find the convex hull of the set of points in O (N*ln (N) where N is the number of points.

Look up for convex hull algorithms, and you can find some ideas.


(*)From wikipedia:

The first step in this algorithm is to find the point with the lowest y-coordinate. If the lowest y-coordinate exists in more than one point in the set, the point with the lowest x-coordinate out of the candidates should be chosen. Call this point P. This step takes O(n), where n is the number of points in question.

Next, the set of points must be sorted in increasing order of the angle they and the point P make with the x-axis. Any general-purpose sorting algorithm is appropriate for this, for example heapsort (which is O(n log n)). In order to speed up the calculations, it is not necessary to calculate the actual angle these points make with the x-axis; instead, it suffices to calculate the cosine of this angle: it is a monotonically decreasing function in the domain in question (which is 0 to 180 degrees, due to the first step) and may be calculated with simple arithmetic.

In the convex hull algorithm you chose the point of the angle that makes the largest angle with the previous side.

To "stick" with your previous polygon, just add the constraint that you must select a side that previously existed.

And you take off the constraint of having angle less than 180°

  1. Remove all the vertices of the polygons which lie inside the other polygon: http://paulbourke.net/geometry/insidepoly/
  2. Pick a starting point that is guaranteed to be in the union polygon (one of the extremes would work)
  3. Trace through the polygon's edges in counter-clockwise fashion. These are points in your union. Trace until you hit an intersection (note that an edge may intersect with more than one edge of the other polygon).
  4. Find the first intersection (if there are more than one). This is a point in your Union.
  5. Go back to step 3 with the other polygon. The next point should be the point that makes the greatest angle with the previous edge.