/Triangulation

This is a fun project

Primary LanguagePython

Triangulation

This project permit to generate faces with points.

To do that I use the Delaunay triangulation algorithm.

How I implement this problem ?

Generate all points

Firstly to generate all points, I decided to give them random positions for x and y for a given number of points. But you can also create two tables, x and y positions, with this solution you will be able to make faces out of a given amoud of points.

Generate all triangles

To make the Delaunay algorithm works you have to create an array which include all triangles you can draw with all points you gave or determined.

So the array will look like that :

array[] = [[A,B,C][A,D,C],...] //depend of the number of point you gave

So first we generate all triangles for example if I choose 4 points it will be : For the point A :

Triangles
ABC
ABD
ACB
ACD
ADB
ADC

We do that for all points.

After that we can see that some triangles are the same like ABD = ADB so we delete one of them, so at the end of the loop we don't have any repetitions.

By analysis table of triangles we can see that the number of triangles for one point which are really useful is :

((nb_point-1) * (nb_point - 2)) / 2

Go to -->scripts/generate_triangle.py to see the code.

Sources :

These links help me a lot to understand how it works.