# Polygon Triangulation with Holes

cgaldirect3dgeometrygraphicstriangulation

I am looking for an algorithm or library (better) to break down a polygon into triangles. I will be using these triangles in a Direct3D application. What are the best available options?

Here is what I have found so far:

1. Ben Discoe's notes
2. FIST: Fast Industrial-Strength Triangulation of Polygons
3. I know that CGAL provides triangulation but am not sure if it supports holes.

I would really appreciate some opinions from people with prior experience in this area.

Edit: This is a 2D polygon.

#### Best Solution

To give you some more choices of libraries out there:

Polyboolean. I never tried this one, but it looks promising: http://www.complex-a5.ru/polyboolean/index.html

General Polygon Clipper. This one works very well in practice and does triangulation as well as clipping and holes holes: http://www.cs.man.ac.uk/~toby/alan/software/

My personal recommendation: Use the tesselation from the GLU (OpenGL Utility Library). The code is rock solid, faster than GPC and generates less triangles. You don't need an initialized OpenGL-Handle or anything like this to use the lib.

If you don't like the idea to include OpenGL system libs in a DirectX application there is a solution as well: Just download the SGI OpenGL reference implementation code and lift the triangulator from it. It just uses the OpenGL-Typedef names and a hand full of enums. That's it. You can extract the code and make a stand alone lib in an hour or two.

In general my advice would be to use something that alreay works and don't start to write your own triangulation.

It is tempting to roll your own if you have read about the ear-clipping or sweep-line algorithm, but fact is that computational geometry algorithms are incredible hard to write in a way that they work stable, never crash and always return a meaningful result. Numerical roundoff errors will accumulate and kill you in the end.

I wrote a triangulation algorithm in C for the company I work with. Getting the core algorithm working took two days. Getting it working with all kinds of degenerated inputs took another two years (I wasn't working fulltime on it, but trust me - I spent more time on it than I should have).