Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygon Triangulation with Holes

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.

like image 655
Agnel Kurian Avatar asked Jan 02 '09 08:01

Agnel Kurian


People also ask

Can polygons have holes?

In geometry, a polygon with holes is an area-connected planar polygon with one external boundary and one or more interior boundaries (holes). Polygons with holes can be dissected into multiple polygons by adding new edges, so they are not frequently needed.

What is polygon triangulation used for?

Computing the triangulation of a polygon is a fundamental algorithm in computational geometry. In computer graphics, polygon triangulation algorithms are widely used for tessellating curved geometries, as are described by splines [Kumar and Manocha 1994].

How many triangulations does a polygon have?

Every triangulation of an n-gon has exactly n − 2 triangles. 3. Polygon in picture has n = 13, and 11 triangles.


1 Answers

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).

like image 186
Nils Pipenbrinck Avatar answered Sep 25 '22 23:09

Nils Pipenbrinck