0

I need to do Delaunay Triangulation for a set of 3D points. I wrote an script for it (below), but it seems to that the output has no tetrahedrons in them. Please give me some inputs/ideas. I am using Python3. Thank you very much.

from scipy.spatial import Delaunay
import matplotlib.pyplot as plt
import numpy as np
points= np.array([[1,2,2],[1,3,6],[4,3,4],[5,3,2]])
tri= Delaunay(points)
fig= plt.figure()
ax= fig.gca(projection= '3d')
ax.plot_trisurf(points[:,0],points[:,1],points[:,2],triangles= tri.simplices)
plt.plot(points[:,0],points[:,1],points[:,2],'+')
plt.show()




Zen
  • 83
  • 2
  • 9

1 Answers1

2

The tetrahedrons are given in the tri.simplices member, which holds an n x 4 array of indices (n being the number of tetrahedrons). The tetrahedron is given as a set of four indices, which correspond to the indices of the four points of the tetrahedron in the points array.

For example the following code will plot the wireframe of the first tetrahedron:

tr = tri.simplices[0]  # indices of first tetrahedron
pts = points[tr, :]  # pts is a 4x3 array of the tetrahedron coordinates

# plotting the six edges of the tetrahedron
for ij in [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]:
    ax.plot3D(pts[ij, 0], pts[ij, 1], pts[ij, 2])

See my previous answers here, here and here for further example code.

Iddo Hanniel
  • 1,636
  • 10
  • 18
  • Thank you. I was able to generate the tetrahedrons. But could you please elaborate what the last two lines do? – Zen May 24 '21 at 20:39
  • They plot the 3d line segments of the tetrahedron. Each of the combinations [0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3] represents an edge of a tetrahedron (e.g., [0, 1] is the edge between vertex 0 of the tetrahedron and vertex 1) so the plot3D function plots a 3D line segment between the corresponding pts. Have a look at the other answers I referenced, which give more elaborate explanations. – Iddo Hanniel May 25 '21 at 09:40
  • Thanks a lot. Your answers were very helpful, including the ones that you referred to. – Zen May 26 '21 at 08:28