# Unions

You could say that recently unions have played a role in my life. First there has been my wedding one and a half week ago of course, forming a nice union between me and my wife. But that is not what I want to talk about in this blog post.

I have also been working on some code that allows me to do boolean operations between polygons. This functionality is something that will come in handy when I start working on my new ground polygon tool, It can for example be used to automatically slice the polygons into piece of no more than 100 meters, so that there are no problems with the curvation of the earth within FSX.

Below you see a screenshot of my test application, where I am testing out these boolean functions. The red polygon is polygon A and the green one is polygon B. The four small pictures below show in grey the union of A and B, the intersection of A and B, polygon A minus B and polygon B minus A respectively.

At first I looked around for some library that implements this functionality and although some exist, I still decided to code it myself in the end. The main reason for that was that I wanted to understand how the process works and that why learn a bit more from it (although it might not always be the easiest way). So in the end I used the algorithms described in Geometric tools for computer graphics and make my own implementation, building further onto for example the polygon class I had already made for ModelConverterX.

The boolean operations are not completely bug free yet, I have already found a few polygons that are not processed correctly. So there is still some more work to do and after that I will start with creating the tool for ground polygons that can make use of this logic. So I still have much more fun ahead…