preveen-stack / nodejs

0 stars 0 forks source link

create step files from python #25

Open preveen-stack opened 6 months ago

preveen-stack commented 6 months ago
import numpy as np
import stl

# Define the geometry of the object
RADIUS = 0.1
HEIGHT = 0.2
RESOLUTION = 30

# Create the mesh data
vertices = []
faces = []

# Define the vertices of the mesh
for i in range(RESOLUTION):
    angle = math.radians(float(i) / RESOLUTION * 360.0)
    x = RADIUS * math.cos(angle)
    y = RADIUS * math.sin(angle)
    z = 0.0
    vertices.append(np.array([x, y, z]))

for i in range(RESOLUTION):
    angle = math.radians(float(i) / RESOLUTION * 360.0)
    x = RADIUS * math.cos(angle)
    y = RADIUS * math.sin(angle)
    z = HEIGHT
    vertices.append(np.array([x, y, z]))

# Define the faces of the mesh
for i in range(RESOLUTION):
    i1 = i
    i2 = (i + 1) % RESOLUTION
    i3 = i + RESOLUTION
    i4 = (i + 1) % RESOLUTION + RESOLUTION
    faces.append([i1, i2, i4])
    faces.append([i1, i4, i3])

# Create the mesh object
mesh_data = np.zeros(len(faces), dtype=stl.mesh.Mesh.dtype)
for i, f in enumerate(faces):
    for j in range(3):
        mesh_data['vectors'][i][j] = vertices[f[j]]
mesh = stl.mesh.Mesh(mesh_data)

# Write the mesh to an STL file
mesh.save('object.stl')