drufat / triangle

Python bindings to the triangle library
GNU Lesser General Public License v3.0
230 stars 53 forks source link

Segments do not work? #11

Closed ChrisVolz closed 5 years ago

ChrisVolz commented 8 years ago

following code should produce a triangulation with enforced segments:

import triangle import triangle.plot from numpy import * import matplotlib.pyplot as plt

pts = array(((0,0), (1,0), (1, 1), (0, 1))) segs2 = array([[0,2],[1,2],[0,1]]) dic = {'vertices':pts, 'segments':segs2}

B = triangle.triangulate(dic) triangle.plot.compare(plt, dic, B) plt.show()

The enforced segments are shown correctly in the plot. However, they are not considered in the triangulation. This seems to be a bug? It woult be cool, to have this problem fixed.

Btw, why does this triangle-wrapper not support 3D points? Triangle supports 3D points and is a nice tool for interpolating 3D data.

FDrico commented 7 years ago

I have the exact same problem: For some reason, the enforced segments are not considered in the triangulation. I had to manually add a set of intermediate points of each segment to the vertices array in order to force the triangulation to include those little segments (they are closer to each other than to any other point).

mccoys commented 7 years ago

Same problem here. Any other workaround that adding extra points?

drufat commented 5 years ago

If you are adding segments, the underlying triangle library requires you to pass the 'p' option in order for it to take those segments into consideration. The code below achieves what you want (with the latest version of triangle).

import triangle import triangle.plot from numpy import * import matplotlib.pyplot as plt

pts = array(((0,0), (1,0), (1, 1), (0, 1))) segs2 = array([[0,2],[1,2],[0,1]]) dic = {'vertices':pts, 'segments':segs2}

B = triangle.triangulate(dic, 'p') triangle.compare(plt, dic, B) plt.show()

Figure_1