Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. from mpl_toolkits.mplot3d import Axes3D
  2. from mpl_toolkits.mplot3d.art3d import Poly3DCollection
  3. import matplotlib.pyplot as plt
  4.  
  5. # x y z
  6. a = (1, 1, 1) # p1
  7. b = (2, 2, 2) # p2
  8.  
  9. x, y, z = 0, 1, 2
  10.  
  11. vertices = [
  12. # XZ
  13. [(a[x], a[y], a[z]), (b[x], a[y], a[z]), (b[x], a[y], b[z]), (a[x], a[y], b[z])],
  14. [(a[x], b[y], a[z]), (b[x], b[y], a[z]), (b[x], b[y], b[z]), (a[x], b[y], b[z])],
  15.  
  16. # YZ
  17. [(a[x], a[y], a[z]), (a[x], b[y], a[z]), (a[x], b[y], b[z]), (a[x], a[y], b[z])],
  18. [(b[x], a[y], a[z]), (b[x], b[y], a[z]), (b[x], b[y], b[z]), (b[x], a[y], b[z])],
  19.  
  20. # XY
  21. [(a[x], a[y], a[z]), (b[x], a[y], a[z]), (b[x], b[y], a[z]), (a[x], b[y], a[z])],
  22. [(a[x], a[y], b[z]), (b[x], a[y], b[z]), (b[x], b[y], b[z]), (a[x], b[y], b[z])],
  23. ]
  24.  
  25. fig = plt.figure()
  26.  
  27. ax = fig.add_subplot(111, projection='3d')
  28.  
  29. ax.plot([a[x], b[x]], [a[y], b[y]], [a[z], b[z]], '-r')
  30. ax.add_collection3d(Poly3DCollection(
  31. vertices, facecolors='cyan', linewidths=1, edgecolors='k', alpha=.2))
  32.  
  33. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement