pythonarraysnumpydelaunaytriangle

How to delete a certain delaunay triangle from the list of tri.simplices in Python


i construct two Delaunay triangulations from two different numpy arrays of vertices.

They have two identical triangles, which i want to delete from one of the triangulation list.

If somebody can help me out here i would really appreciate it. Thanks in advance.


cloud1 = numpy.array([[4.2, 4.5], [4.4, 5.3], [6.2, 5.6], [4.75, 5], [5.2, 4.8]])
cloud2 = numpy.array([[4.2, 4.5], [4.4, 5.3], [6.2, 5.6], [4.75, 5]])


tri1 = scipy.spatial.Delaunay(cloud1)
tri2 = scipy.spatial.Delaunay(cloud2)

print(tri1.simplices)
print("*************")
print(tri2.simplices)

It gives that

[[1 3 2]
 [3 4 2]
 [3 1 0]
 [4 3 0]]
*************
[[2 3 0]
 [3 1 0]
 [1 3 2]]

I wrote this but it doesn't work.

for i in range(0,len(tri1.simplices)):
    if (tri1.simplices[i] in tri2.simplices):
        numpy.delete(tri1.simplices, tri1.simplices[i])
    else:
        continue




Solution

  • If you want to delete a triangle from the Delaunay triangulation itself, then it isn't possible in Delaunay triangulations. There are algorithms for removing points from the triangulation, which re-build the triangulation in the area of the removed points. However, to the best of my knowledge, they are not implemented in scipy's Delaunay triangulation.

    Still, if you just want to compare two triangulations and remove triangles from the list of simplices (for example for drawing), then you can copy the simplices list and manipulate the copy as is done in this answer.

    Note that in you question you compare the simplices list directly. However, the simplices array holds indices of the points and not the points themselves. What you probably want to do is compare the array of points, not the indices. For example, with some code like this:

    tr1 = tri1.simplices[0]  # indices of first triangle in tri1
    pts1 = tri1.points[tr1, :]  # pts1 is a 3x2 array of the first triangle coordinates
    

    Or to get the full array of triangle points:

    tri1_pts = tri1.points[tri1.simplices]  # (n, 3, 2) array - triangles as points (not indices)