#!/usr/bin/env python3 """Generate a synthetic scan-like STL: a flat datum grid at z=0 plus a cylindrical hole wall (radius 5 mm, axis +z) spanning z in [-6, 0]. Binary STL.""" import struct, math, sys tris = [] # each: (nx,ny,nz, v0,v1,v2) def tri(a, b, c): ux, uy, uz = b[0]-a[0], b[1]-a[1], b[2]-a[2] vx, vy, vz = c[0]-a[0], c[1]-a[1], c[2]-a[2] nx, ny, nz = uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx L = math.sqrt(nx*nx+ny*ny+nz*nz) or 1.0 tris.append((nx/L, ny/L, nz/L, a, b, c)) # flat datum grid z=0, [-20,20]^2, skip the hole region N = 24 lo, hi = -20.0, 20.0 step = (hi-lo)/N R = 5.0 def inhole(x, y): return x*x + y*y < (R+0.5)**2 for i in range(N): for j in range(N): x0, y0 = lo+i*step, lo+j*step x1, y1 = x0+step, y0+step if inhole((x0+x1)/2, (y0+y1)/2): continue a=(x0,y0,0.0); b=(x1,y0,0.0); c=(x1,y1,0.0); d=(x0,y1,0.0) tri(a,b,c); tri(a,c,d) # cylindrical hole wall, radius R, z in [-6,0], normals pointing inward (toward axis) M = 48 z0, z1 = -6.0, 0.0 for k in range(M): t0 = 2*math.pi*k/M t1 = 2*math.pi*(k+1)/M p00=(R*math.cos(t0), R*math.sin(t0), z0) p10=(R*math.cos(t1), R*math.sin(t1), z0) p01=(R*math.cos(t0), R*math.sin(t0), z1) p11=(R*math.cos(t1), R*math.sin(t1), z1) # wind so normals face the axis (inward) tri(p00,p01,p11); tri(p00,p11,p10) path = sys.argv[1] if len(sys.argv) > 1 else "test_plate.stl" with open(path, "wb") as f: f.write(b"\0"*80) f.write(struct.pack("