如何绘制三角形3D网格

问题描述

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

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

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

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

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

解决方法

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

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

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

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

plt.show()

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...