2016-12-30 108 views
1

我想matplotlib繪製一個四面體網格,下面是一個簡單的四面體網格:如何通過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) 
+0

閱讀:https://mathema.tician.de/software/meshpy/ – eyllanesc

+0

和這個:https://github.com/inducer/meshpy/blob/master/examples/test_tri_quadratic.py – eyllanesc

回答

1

matplotlib或許是任務的錯誤的工具。 3D繪圖很難,例如有ParaView可以試用。您可以使用meshio(我的項目)到您的目寫入適當的數據類型:

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

enter image description here

+0

這是一個很好的工作。 'meshio'可以讀取和寫入obj網格文件嗎? –

+0

從來沒有聽說過這種格式。 –

+0

以下是wiki https://en.wikipedia.org/wiki/Wavefront_.obj_file。 –

1

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