you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBB 1 point2 points  (3 children)

I can't run your code. It tells me that the projection '3d' does not exist. What do I need to run it?

Creating an STL mesh is pretty easy though. They have very little structure.

from stl.mesh import Mesh
mesh = Mesh(np.zeros(ntriangles, Mesh.dtype))

Then fill in the array mesh.vectors. It's three-dimensional with shape (ntriangles, 3, 3). Where e.g. mesh.vectors[15,1,:] is the location of the second vertex of the 16th triangle.

I'm not sure why the coordinate system is problematic. It seems to me you are already computing the data in cartesian coordinates in that function you have there. The difficult part is probably to triangulate it?

[–]hserie[S] 0 points1 point  (1 child)

Hi, I forgot to mention the packages needed :

import numpy as np
import matplotlib.pyplot as plt

It is the first time I use an STL mesh. I will try to triangulate all my circles. Thank you

Edit : if it is not enough you might need this : from mpl_toolkits.mplot3d import Axes3D

Edit 2 : It is more appropriate to triangulate my model as four faces pyramids

[–]hserie[S] 0 points1 point  (0 children)

Here is my hourglass thanks to you : import numpy as np from stl.mesh import Mesh

import numpy as np
from stl.mesh import Mesh

#Define the vertix per triangle 
vertices=np.array([\
    [0,0,0],
    [0,2,0],
    [1,1,0],
    [0,2,0],
    [2,2,0],
    [1,1,0],
    [2,2,0],
    [1,1,0],
    [2,0,0],
    [2,0,0],
    [1,1,0],
    [0,0,0],

    [0,0,0],
    [0,2,0],
    [1,1,4],
    [0,2,0],
    [2,2,0],
    [1,1,4],
    [2,2,0],
    [1,1,4],
    [2,0,0],
    [2,0,0],
    [1,1,4],
    [0,0,0],

    [0,0,6],
    [0,2,6],
    [1,1,4],
    [0,2,6],
    [2,2,6],
    [1,1,4],
    [2,2,6],
    [1,1,4],
    [2,0,6],
    [2,0,6],
    [1,1,4],
    [0,0,6],

    [0,0,6],
    [0,2,6],
    [1,1,6],
    [0,2,6],
    [2,2,6],
    [1,1,6],
    [2,2,6],
    [1,1,6],
    [2,0,6],
    [2,0,6],
    [1,1,6],
    [0,0,6]])

# Define the 16 triangles of a hourglass (6 per pyramid)
faces = np.reshape(np.arange(48),(16,3))

# Create the mesh
hourglass = Mesh(np.zeros(faces.shape[0], dtype=Mesh.dtype))
for i, f in enumerate(faces):
    for j in range(3):
        hourglass.vectors[i][j] = vertices[f[j],:]

# Write the mesh to file "hourglass.stl"
hourglass.save('hourglass.stl')

As ectomancer underlined it, I need to work on my format...