如何用matplotlib绘制四面体网格?

2024-05-23 13:34:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用matplotlib绘制一个四面体网格,下面是一个简单的四面体网格:

xyz = np.array([
    [-1,-1,-1],
    [ 1,-1,-1], 
    [ 1, 1,-1],
    [-1, 1,-1],
    [-1,-1, 1],
    [ 1,-1, 1], 
    [ 1, 1, 1],
    [-1, 1, 1]], dtype=np.float) 

tets = np.array([
    [0,1,2,6],
    [0,5,1,6],
    [0,4,5,6],
    [0,7,4,6],
    [0,3,7,6],
    [0,2,3,6]], dtype=np.int)

当然,在实际应用中,网格中的四面体数目可能很大。我在谷歌上找不到任何有用的帮助信息。那么,用matplotlib绘制四面体网格的更好方法是什么?在

此外,我可以得到网格的所有三角形面。在

^{pr2}$

Tags: 方法信息网格matplotlibnp绘制floatarray
2条回答

matplotlib可能是这个任务的错误工具。三维绘图很难,而且有,例如,ParaView来尝试。您可以使用meshio(我的一个项目)将网格写入适当的数据类型:

import meshio
meshio.write('out.vtu', xyz, {'tetra': tets})

enter image description here

可以使用mpl_toolkits.mplot3d.art3d.Poly3DCollection

import mpl_toolkits.mplot3d as a3
axes = a3.Axes3D(pl.figure())
vts = xyz[tri, :]
tri = a3.art3d.Poly3DCollection(vts)
tri.set_alpha(0.2)
tri.set_color('grey')
axes.add_collection3d(tri)
axes.plot(point[:,0], point[:,1], point[:,2], 'ko')
axes.set_axis_off()
axes.set_aspect('equal')
pl.show()

相关问题 更多 >