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

Python 3.x 如何在Python中从3D点的Delaunay三角剖分生成四面体?,python-3.x,plot,3d,delaunay,Python 3.x,Plot,3d,Delaunay,我需要对一组3D点进行Delaunay三角剖分。我为它写了一个脚本(如下),但似乎输出中没有四面体。请给我一些意见/想法。我在用蟒蛇3。多谢各位 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()

我需要对一组3D点进行Delaunay三角剖分。我为它写了一个脚本(如下),但似乎输出中没有四面体。请给我一些意见/想法。我在用蟒蛇3。多谢各位

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
成员中给出,该成员拥有一个
nx4
索引数组(n是四面体的数目)。四面体由四个索引组成,对应于
数组中四面体四个点的索引

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

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

请参阅我以前的答案,以及更多示例代码。

谢谢。我能够生成四面体。但你能详细说明最后两条线是做什么的吗?它们绘制了四面体的三维线段。[0,1]、[0,2]、[0,3]、[1,2]、[1,3]、[2,3]组合中的每一个表示四面体的边(例如,[0,1]是四面体的顶点0和顶点1之间的边),因此plot3D函数在相应的PT之间绘制3D线段。看看我提到的其他答案,它们给出了更详细的解释。非常感谢。你的回答很有帮助,包括你提到的那些。