简体   繁体   English

如何绘制三角形 3d 网格

[英]How to plot a triangular 3d mesh

In 2d it is quite simple to plot a triangular mesh given by the vertices and the 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()

Now I'd like to do the exact same thing but in three dimension, that is with eg现在我想做完全相同的事情,但在三维空间中,例如

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

Is there a simple way to achieve that in matplotlib?有没有一种简单的方法可以在 matplotlib 中实现? (At least simpler than looping over the triangles and plotting the edges manually?) (至少比在三角形上循环并手动绘制边缘更简单?)

You can achieve it in a very similar way using mplot3d :您可以使用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()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM