algorithmgraphicstopologytesselation

How to convert a polygon to a set on non-overlapping triangles?


I have a coordinate set of 2D points that form a closed polygon. I need to generate a set of 2D triangles that distribute the polygon completely.

There are no constrains as such except that the triangles should fill the area of polygon completely. It would be even more helpful if it is a standard algorithm I could implement.


Solution

  • As mentioned above, Delaunay triangulation is a rather complicated algorithm for this task. If you accept O(n^2) running time, you may try Ear Clipping algorithm which is much more easier to understand and to code. The basic idea is the following. Every polygon with >= 4 vertexes and no holes (i.e. its border is a single polyline without self-intersections and self-tangencies) has at least one "ear". An ear is a three consecutive vertexes such that the triangle built on them lies inside the polygon and contains no other points of the polygon inside. If you "cut an ear" (add a triangle to the answer and replace remove the middle point of these three points), you reduce the task to a polygon with less vertexes, and so on. Ears may be trivially (by definition) found in O(n^2) resulting in a O(n^3) triangulation algorithm. There is O(n) ear finding algorithm, and, though it is not very complicated, it is rather long to be described in a couple of phrases.

    Furthermore, if you need faster algorithms, you should look something about monotone polygons triangulation and splitting a polygon into monotone ones. There even exists a linear-time triangulation algorithm, but its just as complicated as Delaunay triangulation is.

    You may consider Wikipedia article and see an small overview of existing methods there.