I know how to get the union of two polygons
But I don't have time to program it so I'll just explain it:
You need to know how to do a line/line intersection test, but that is easily available on the internet.
- Take a point on one of the polygons, which is outside the other polygon. (You can check if it is outside by checking for intersections using a horizontal line away from the point a long way away. If it intersects with an even number of lines from the other polygon, it is outside the polygon.)
- Follow the points around that polygon starting with that point.
- For each line on the polygon defined by the current point and the previous point, check if it intersects with any lines from the other polygon.
- If it does intersect, add a point at the intersection, and continue on the new line you found, starting from the new point.
- Once you get back to the start you have drawn a union of the two polygons.