import json,numpy as np from geom import D1,D2 R=json.load(open('results.json')); L=R['L_mm']; W=270.0; off=30.0 bolts=[(15,15),(135,15),(255,15),(15,135),(255,135),(15,255),(135,255),(255,255)] def tomm(P): return [(off+x*L, W-(off+y*L)) for x,y in P] # y flipped for SVG/DXF consistency (y down) def svg(polys,circles,name,label): s=[f'', f'', f''] for P in polys: s.append('') for (x,y,r) in circles: s.append(f'') s.append(''); open(f'out/cut/{name}.svg','w').write('\n'.join(s)) d=['0','SECTION','2','ENTITIES'] def line(a,b): d.extend(['0','LINE','8','CUT','10',f'{a[0]:.4f}','20',f'{W-a[1]:.4f}','11',f'{b[0]:.4f}','21',f'{W-b[1]:.4f}']) box=[(0,0),(W,0),(W,W),(0,W)] for P in [box]+polys: for i in range(len(P)): line(P[i],P[(i+1)%len(P)]) for (x,y,r) in circles: d.extend(['0','CIRCLE','8','CUT','10',f'{x:.4f}','20',f'{W-y:.4f}','40',str(r)]) d.extend(['0','ENDSEC','0','EOF']); open(f'out/cut/{name}.dxf','w').write('\n'.join(d)+'\n') B=[(x,y,2.75) for x,y in bolts] for dn,P in (('D1',D1),('D2',D2)): poly=tomm(P) svg([poly],B,f'{dn}_frame',f'{dn} frame: cut 2 for the membrane sandwich, or 2 in 3mm acrylic as the cavity spacer') pr=R['ports'][dn]; ports=[(off+pr[k][0]*L, W-(off+pr[k][1]*L), 2.0) for k in ('speaker','mic')] svg([],B+ports,f'{dn}_lid',f'{dn} cavity lid: 4mm speaker port then mic port, at drum coords {pr["speaker"]} and {pr["mic"]}') svg([],B,'base','cavity base, cut 2 (one per drum)') print(open('out/cut/D1_frame.svg').read()[:600])