简体   繁体   中英

Draw 3D Polygon Using Vertex Array Python (Matplotlib)

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!

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM