Reputation: 779
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!
Upvotes: 1
Views: 3816
Reputation: 920
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()
Upvotes: 1