Delaunay Triangulation(Python,C++)

Hi everyone. I was loking for a triangulation algorithm to use instead scipy and I find this: https://github.com/mapbox/delaunator

But its written for js so I ported it to python.

Python port: https://github.com/HakanSeven12/Delaunator-Python

Also it has a C++ port: https://github.com/delfrrr/delaunator-cpp

If you interested with irregular points triangulation you can use it.

Test for FreeCAD:

from Delaunator import Delaunator
import numpy as np
import Mesh
import FreeCAD as App

points = np.random.randint(1,1677.7215,size=(10000,2))
triangles = Delaunator(points).triangles

coords = [App.Vector(i[0], i[1]) for i in points]
facets = list(tuple([triangles[x+2],triangles[x+1],triangles[x]]) for x in range(0, len(triangles), 3)) 

mesh = Mesh.Mesh()
mesh.addFacets((coords, facets))
Mesh.show(mesh)

Nice.

Btw, to extend your example, here is how the triangulation can be transferred to FreeCAD:

from Delaunator import Delaunator
import numpy as np
import Mesh
import FreeCAD as App

points = np.random.randint(4000000,4500000,size=(100000,2))
triangles = Delaunator().run(points)

coords = [App.Vector(i[0], i[1]) for i in points]
facets = list(tuple(triangles[x:x + 3]) for x in range(0, len(triangles), 3)) 

mesh = Mesh.Mesh()
mesh.addFacets((coords, facets))
Mesh.show(mesh)

Its also implemented to Geomatics Workbench: https://github.com/HakanSeven12/FreeCAD-Geomatics-Workbench/blob/master/Surfaces/CreateSurface.py#L156-L180

Does it support holes and concave boundary?

No, it’s not a constrained Delaunay but a normal Delaunay triangulation.

IIRC, this one is a CDT: https://www.cs.cmu.edu/~quake/triangle.html

Yes I am aware of triangle and python bindings via meshpy. I also worked on a triangulation tool [1] but never reached scipy speeds (trying to acelerate with numba). How does this library compares to scipy? If it’s really faster, would it be possible to add the concave-boundary and hole removal functionality?

[1] https://github.com/booya-at/poly-tri

What time does scipy take for 100 000 scattered points? This algorithm takes ~17 sec on my computer.

Btw, this algorithm seems to only work for scattered points when three adjacent points always form a real triangle. As soon as they are collinear the algorithm stops with a division-by-zero exception. This means for structured clouds where the points are organized in a grid structure it cannot be used.

Yes, that seems to be quite good, but compared to triangle (meshpy) and scipy about 10 times slower. The comparison to polytri is not really fair as polytri produce a non-delaunay triangulation.
delauny_comparison.png

Hi. Can I use your comparison results on my repo “readme”?

sure.

Thanks