Trying to triangulate a set of simple 2d polygons, I\'ve come up with this algorithm:
While ear clipping works reasonably well, simplistic methods slow down as the polygon increases in complexity since checking the entire polygon when collapsing each ear becomes increasingly slow.
The ear clipping algorithm from libgdx
is a good place to start from, since its very robust - using FIST (Fast Industrial-Strength Triangulation of Polygons).
I used this as a basis for polygon tessellation, then added spatial optimizations for the point-in-triangle tests, (O(n log n)
instead of O(n^2)
).
See:
Note, while the algorithm doesn't explicitly support holes, you can use keyhole edges between separate islands, which will then be correctly triangulated.