我有一个由Meshlab用顶点和面数据生成的OBJ文件。在MATLAB中,我对1个数组(5937x3)中的Vertices数据和另一个数组中的Faces(11870x3)数据使用了``patch''函数,结果是这样的:
Simplified version of the code
[V,F] = read_vertices_and_faces_from_obj_file(filename);
patch('Vertices',V,'Faces',F,'FaceColor','r','LineStyle','-')
axis equal
问题是,如何在Python中做到这一点?有一个简单的方法,例如在Matlab中?
我将非常感谢您的帮助。
您最好的选择是利用的mplot3d
工具从matplotlib
库。
这里也提出了类似的问题。也许从这个问题中摘录的经过稍微编辑的代码片段将对您有所帮助。
代码:
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
# Specify 4 vertices
x = [0,1,1,0] # Specify x-coordinates of vertices
y = [0,0,1,1] # Specify y-coordinates of vertices
z = [0,1,0,1] # Specify z-coordinates of vertices
verts = [zip(x, y, z)] # [(0,0,0), (1,0,1), (1,1,0), (0,1,1)]
tri = Poly3DCollection(verts) # Create polygons by connecting all of the vertices you have specified
tri.set_color(colors.rgb2hex(sp.rand(3))) # Give the faces random colors
tri.set_edgecolor('k') # Color the edges of every polygon black
ax.add_collection3d(tri) # Connect polygon collection to the 3D axis
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句