This project is read-only.

Carving a polygon using holes

Sep 1, 2016 at 5:29 PM
I'm trying to find a way to carve a polygon using hole, but it's not behaving as I would want it. Is there a way to do this? Currently I'm adding the carving polygon as a hole.
Images are more explanatory, so here goes:

How it triangulates it now:

What I'm trying to achieve:

Any help is super appreciated!


Also, thanks a bunch for this code so far, it has been working great for us :)
Sep 9, 2016 at 2:24 PM
Let A be the bigger square and B the smaller one. You want to compute the difference of the polygons, A \ B. If B lies inside of A, this can be done with Triangle, since B can be treated as a hole.

In your second case, B obviously isn't a hole. The main problem is (taking the above graphic as an example), that B gets split into two parts, while only one part can be specified as a hole (either the top or the bottom). The other part is protected by the top segment of A.

You could do polygon clipping before triangulation (
Sep 10, 2016 at 6:05 PM
Edited Sep 10, 2016 at 6:08 PM
I have updated the RegionIterator class, which might be another option for you.

See Example 7 - Boolean operations on meshes
Sep 12, 2016 at 6:07 PM
I ended up using Clipper in combination with Triangle, thanks a bunch for your response :)