CubeV2.py 748 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. from stl import mesh
  2. import numpy as np
  3. # Définir les sommets du cube
  4. vertices = np.array([
  5. [-1, -1, -1],
  6. [+1, -1, -1],
  7. [+1, +1, -1],
  8. [-1, +1, -1],
  9. [-1, -1, +1],
  10. [+1, -1, +1],
  11. [+1, +1, +1],
  12. [-1, +1, +1]
  13. ])
  14. # Définir les faces du cube (triangles individuels)
  15. faces = np.array([
  16. [0, 1, 2],
  17. [0, 2, 3],
  18. [0, 4, 5],
  19. [0, 5, 1],
  20. [1, 5, 6],
  21. [1, 6, 2],
  22. [2, 6, 7],
  23. [2, 7, 3],
  24. [3, 7, 4],
  25. [3, 4, 0],
  26. [4, 7, 6],
  27. [4, 6, 5]
  28. ])
  29. # Créer le maillage STL
  30. cube = mesh.Mesh(np.zeros(faces.shape[0], dtype=mesh.Mesh.dtype))
  31. for i, f in enumerate(faces):
  32. cube.vectors[i] = vertices[f]
  33. # Sauvegarder le cube au format STL
  34. cube.save('cube.stl')