【问题标题】:How to draw a Tetrahedron mesh by matplotlib?如何通过 matplotlib 绘制四面体网格?
【发布时间】:2016-12-30 23:45:35
【问题描述】:

我想通过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)

当然,在实际应用中,一个网格中的四面体的数量可以很大。我在 google 中找不到任何有用的帮助信息。那么通过matplotlib 绘制四面体网格的更好方法是什么?

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

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

【问题讨论】:

    标签: python matplotlib tetrahedra


    【解决方案1】:

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

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

    【讨论】:

    • 这是一部好作品。 meshio可以读写obj网格文件吗?
    • 如果meshio 可以在调试时使用matplotlib 来绘制网格就好了
    【解决方案2】:

    可以使用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()
    

    【讨论】:

      猜你喜欢
      • 2016-02-06
      • 2018-02-10
      • 1970-01-01
      • 2014-06-14
      • 1970-01-01
      • 2020-08-15
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多