【问题标题】:How can I generate tetrahedrons from the Delaunay triangulation of 3D points in Python?如何从 Python 中的 3D 点的 Delaunay 三角剖分生成四面体?
【发布时间】:2021-08-11 13:04:59
【问题描述】:

我需要对一组 3D 点进行 Delaunay 三角剖分。我为它写了一个脚本(如下),但似乎输出中没有四面体。请给我一些意见/想法。我正在使用 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()




【问题讨论】:

    标签: python-3.x plot 3d delaunay


    【解决方案1】:

    四面体在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])
    

    更多示例代码请参见我之前的回答 hereherehere

    【讨论】:

    • 谢谢。我能够生成四面体。但是你能详细说明最后两行的作用吗?
    • 他们绘制了四面体的 3d 线段。 [0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3] 的每个组合表示四面体的边(例如,[0 , 1] 是四面体的顶点 0 和顶点 1) 之间的边,因此 plot3D 函数在相应点之间绘制 3D 线段。看看我引用的其他答案,它们给出了更详细的解释。
    • 非常感谢。您的回答非常有帮助,包括您提到的那些。
    猜你喜欢
    • 2019-06-10
    • 1970-01-01
    • 2019-04-18
    • 2015-06-30
    • 2013-11-30
    • 2012-05-25
    • 1970-01-01
    • 2010-12-23
    • 2015-01-07
    相关资源
    最近更新 更多