Reputation: 23
I have an OBJ File Generated by Meshlab with Vertices and Faces data. In MATLAB i used the function ''patch'' with Vertices data in 1 array (5937x3) and Faces (11870x3) data in another and the result is this:
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
The question is,how can I do that in Python ? There's a simple way like in Matlab??
I'll really appreciate any help.
Upvotes: 2
Views: 1000
Reputation: 1684
Your best bet would be to make use of the mplot3d
toolkit from the matplotlib
library.
A similar question was asked here. Perhaps this slightly edited code excerpt from that question will help you.
The Code:
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()
Upvotes: 2