如何从 Python 中的 3D 点的 Delaunay 三角剖分生成四面体?

How can I generate tetrahedrons from the Delaunay triangulation of 3D points in Python?

我需要对一组 3D 点进行 Delaunay 三角剖分。我为它写了一个脚本(如下),但似乎输出中没有四面体。请给我一些inputs/ideas。我正在使用 Python3。非常感谢。

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()




四面体在 tri.simplices 成员中给出,它包含一个 n x 4 索引数组(n 是四面体的数量)。四面体作为一组四个索引给出,它们对应于 points 数组中四面体的四个点的索引。

例如,以下代码将绘制第一个四面体的线框:

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])

查看我之前的回答 here, here and 以获取更多示例代码。