2

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

Result

The question is,how can I do that in Python ? There's a simple way like in Matlab??

I'll really appreciate any help.

1 Answer 1

2

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! I'll try that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.