如何绘制三角形3D网格

时间:2020-08-26 15:45:48

标签: python-3.x matplotlib mesh triangulation

在2d中绘制由顶点和三角剖分给出的三角形网格非常简单

import matplotlib.pyplot as plt
import numpy as np
T = np.array([[0,1,2], [1,2,3]])
vertices = np.array([[0,0],[1,0],[0,1],[1,2]])
plt.triplot(vertices[:,0], vertices[:,1], T)
plt.show()

现在我想做的是完全相同的事情,但是要在三维上做,例如。

vertices = np.array([[0,0,0],[1,0,0],[0,1,0],[1,2,1]])

在matplotlib中有一种简单的方法可以实现吗? (至少比在三角形上循环并手动绘制边缘更简单?)

1 个答案:

答案 0 :(得分:2)

您可以使用mplot3d以非常相似的方式实现它:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

vertices = np.array([[0,0,0],[1,0,0],[0,1,0],[1,2,1]])
T = np.array([[0,1,2], [1,2,3]])

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(vertices[:,0], vertices[:,1], vertices[:,2], triangles = T, edgecolor=[[0,0,0]], linewidth=1.0, alpha=0.0, shade=False)

plt.show()

enter image description here

相关问题