tripy icon indicating copy to clipboard operation
tripy copied to clipboard

3D possible?

Open sweco-sekrsv opened this issue 4 years ago • 1 comments

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

sweco-sekrsv avatar Nov 14 '19 22:11 sweco-sekrsv

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

MartinFalatic avatar Nov 15 '19 11:11 MartinFalatic