2

I have already downloaded the Numpy-stl library but I am not sure how a general export would work for a simple code for example a cube? So, if I plot a Cube in Matplotlib, and want to export it to an .stl file to be able to open in CAD, how should I do it? I would also appreciate if someone can kindly explain what triangulation is about!! I am new to coding..

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations


fig = plt.figure()

ax = fig.gca(projection='3d')

ax.set_aspect("auto")

# draw cube

r = [-1, 2]

for s, e in combinations(np.array(list(product(r, r, r))), 2):

    if np.sum(np.abs(s-e)) == r[1]-r[0]:

        ax.plot3D(*zip(s, e), color="b")
Arpan Ray
  • 21
  • 1
  • I know little of this, but looking at the documentation and what you've written, there's apparently a discrepancy. Your plot is just a bunch of lines. What stl requires is the vertices and tris, not as a graph. Plotting would be useful for visualization. Check this source: https://catonif.github.io/cube/ and this example in the documentation and see if that helps. https://numpy-stl.readthedocs.io/en/latest/usage.html#creating-mesh-objects-from-a-list-of-vertices-and-faces – K.Cl Apr 03 '21 at 19:03
  • And also https://stackoverflow.com/questions/56545819/is-there-a-way-to-export-an-stl-file-from-a-matplotlib-surface-plot and https://github.com/WoLpH/numpy-stl/issues/19 – K.Cl Apr 03 '21 at 19:05
  • 1
    Wow I didn't find that documentation myself for some reason.. now its totally clear to me! Thanks a lot.. – Arpan Ray Apr 04 '21 at 20:29

0 Answers0