1

I need to draw polygons using vertex arrays in the form P = (X, Y, Z), a Cube would be represented by:

P1 = [0,0,0]
P2 = [0,1,0]
P3 = [1,0,1]
P4 = [0,1,1]
P5 = [1,1,1]
P6 = [1,1,0]
P7 = [1,0,0]
P8 = [0,0,1]

With that given I want to be able to draw the lines between the points and show the object in 3D, I already have matplotlib installed but if you have the solution for it using another library it's totally fine. By the way, I've already searched for similar topics but couldn't find help, I have also read the matplotlib docs but didn't find a way to do this. Plotting 3D Polygons in python-matplotlib this doesnt either... Thanks!

1 Answer 1

1

You need to use mplot3d along with basic pyplot:

 from mpl_toolkits.mplot3d import Axes3D
 import matplotlib.pyplot as plt
 from mpl_toolkits.mplot3d.art3d import Poly3DCollection
 fig = plt.figure()
 ax = Axes3D(fig)
 vertices = [zip(P1,P2,...)]
 ax.add_collection3d(Poly3DCollection(vertices))
 plt.show()
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the quick answer, but I get the error: "object of type 'zip' has no len()" I think it has something to do with python 3

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.