linuxlewis / tripy

Simple polygon triangulation algorithms in pure python
MIT License
64 stars 10 forks source link

3D possible? #4

Open sweco-sekrsv opened 4 years ago

sweco-sekrsv commented 4 years ago

Hi! Is it possible to add a third dimension to the function?(z height) Something like: polygon = [(0,1,2), (-1, 0, 2.5), (0, -1, 2.5), (1, 0, 2)]

I tried it but get the error: triangles = tripy.earclip(polygon)

 File "C:\Users\SEKRSV\AppData\Local\Programs\Python\Python36\lib\site-packages\tripy.py", line 30, in earclip
    polygon = [Point(*point) for point in polygon]
  File "C:\Users\SEKRSV\AppData\Local\Programs\Python\Python36\lib\site-packages\tripy.py", line 30, in <listcomp>
    polygon = [Point(*point) for point in polygon]
TypeError: __new__() takes 3 positional arguments but 4 were given
MartinFalatic commented 4 years ago

The problem in 3D space is quite a bit more complicated than on a single plane. While technically one can calculate the area of a triangle in 3D space with nearly as much ease as 2D, the surface itself depends on the points chosen. At a first glance I think this would be far more complicated than this library would provide.

However, for this class of problem in 3D you might want to look into Delaunay triangulation:

https://www.youtube.com/watch?v=63MM0EqXlT0

See also SciPy's implementation:

https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.spatial.Delaunay.html