cutdepth = 55 rf = 67 # FIRSTLY, ROUGHLY CUT THE FACES: phi = 0.5 + np.sqrt(1.25) pentag = 0.5 * np.array([[phi, 1 - phi, -2, 1 - phi, phi], [ np.sqrt(3 - phi), np.sqrt(phi + 2), 0, -np.sqrt(phi + 2), -np.sqrt(3 - phi) ], [0, 0, 0, 0, 0]]).T # facial planar exradius = 1 verts = np.vstack((rf * pentag - np.array([[0, 0, cutdepth]]), (rf + cutdepth * (phi - 1)) * pentag)) verts += np.random.normal(scale=1e-6, size=verts.shape) pt = cnc.polyTri(facets=np.empty((0, 3, 3))) pt.addConvexPolygon(verts[:5, :]) pt.addConvexPolygon(verts[[0, 1, 6, 5], :]) pt.addConvexPolygon(verts[[1, 2, 7, 6], :]) pt.addConvexPolygon(verts[[2, 3, 8, 7], :]) pt.addConvexPolygon(verts[[3, 4, 9, 8], :]) pt.addConvexPolygon(verts[[4, 0, 5, 9], :]) pg = pt.toPG(offset) tp0 = pg.MultiToolGreedy(0, [{ 'bitrad': ballrad, 'cude': cude, 'ds': 1 }], yinc=True)[0]
# Load an stl file, transform it into relief and save gcode. import cnc import numpy as np import matplotlib.pyplot as plt import scipy.stats import sys if len(sys.argv) != 5: print("Usage: python relief.py modName height depth bkgRad") else: modName = sys.argv[1] (height, depth, bkgRad) = tuple(float(a) for a in sys.argv[2:]) pt = cnc.polyTri(f"./{modName}.stl") print(pt) # Assume raw model height & depth are both 1. Scale as required: pt = pt.afxform( np.array([[height, 0, 0, 0], [0, height, 0, 0], [0, 0, depth, 0], [0, 0, 0, 1]])) # Also add a floor at (0,0,-depth) of radius bkgRad: sector = 2 * np.pi / 30 for n in range(30): pt.addConvexPolygon( np.array([[0, 0, -depth], [ bkgRad * np.cos(n * sector), bkgRad * np.sin(n * sector), -depth ], [
# Load the .stl file for Merry Cretaceousmas exported from Blender, and create # Gcode to cut it. import cnc pt = cnc.polyTri("./Dinos.stl") # Convert from m to mm: pt = pt.afxform([[1e3,0,0,0],[0,1e3,0,0],[0,0,1e3,0],[0,0,0,1]]) print(pt) pg = pt.toPG(0.3) tp = pg.SingleToolNoOpt(1) tp.PathToGCode(1000, "dinos.gcode")
mxr = np.array([-0.325, 0.5]) nxr = np.array([0, 100]) myr = np.array([-0.8, 0.8]) nyr = np.array([-(5 + (np.diff(nxr) * np.diff(myr) / np.diff(mxr))[0]), -5]) # to keep the xy aspect unchanged multiplier = 1.21 xdir = True ################################################################################################################## # LOAD AND MANIPULATE: pt = cnc.polyTri("./BasRelief.stl") print(pt) oldz = pt.facets[:, :, 2, None] midz = mzr[0] + (mzr[1] - mzr[0]) * (oldz - ozr[0]) / (ozr[1] - ozr[0]) pt.facets *= midz / oldz scjac = np.array([ (nxr[1] - nxr[0]) / (mxr[1] - mxr[0]), # scale Jacobian (nyr[1] - nyr[0]) / (myr[1] - myr[0]), (nzr[1] - nzr[0]) / (mzr[1] - mzr[0]) ]) scint = np.array([ nxr[0], nyr[0], nzr[0] ]) - np.array([mxr[0], myr[0], mzr[0]]) * scjac # scale intercept pt.facets = multiplier * (scint[None, None, :] +
# Load the Monty stl exported from Blender, and convert it to g-code. import cnc import numpy as np pt = cnc.polyTri("./Monty.stl") # Blender has measured in metres, whereas we're using mm, so need to multiply # everything by 1000: pt = pt.afxform(np.diag([1000, 1000, 1000, 1])) # print(pt.bbox()) if False: # This was all good, but we're just doing spots now. # Do the rough cut: pg = pt.toPG(1.0) tp = pg.MultiToolGreedy(0, [dict(bitrad=3.0, cude=3.0, ds=1)])[0] # tp = pg.SingleToolNoOpt(3.0) tp.PathToGCode(1200, "monty_rough.gcode") # Do spots! pg = pt.toPG(0.3, yrange=[22, 68]) tp = pg.SingleToolNoOpt(1.0) tp.PathToGCode(1200, "monty_spot.gcode") pg = pt.toPG(0.3, xrange=[170, 215], yrange=[24, 36]) tp = pg.SingleToolNoOpt(1.0) tp.PathToGCode(1200, "monty_mast.gcode") # Do the fine cut: pg = pt.toPG(0.3) tp = pg.SingleToolNoOpt(1.0)
# Load an stl file designed for 3D printing (downloaded from the internet) and manipulate it to produce code for # CNC carving. import cnc import numpy as np import matplotlib.pyplot as plt import scipy.stats ################################################################################################################## # PARAMETERS: ################################################################################################################## # LOAD AND MANIPULATE: pt = cnc.polyTri("./Full_Bus.stl") # Full_Bus.stl") print(pt) # A = np.identity(4) # A[:3,:3] = scipy.stats.special_ortho_group.rvs(3) # Add label before transformations: w = 0.2 phi = np.pi / 4 + np.arcsin(w / np.sqrt(8)) x = 1 - w / np.sin(phi) - w / np.tan(phi) glyph = np.array([[-1, 1], [-1, 1 - w], [x, 1 - w], [1, 1]]) glyph = np.concatenate((glyph, -glyph)) T = np.array([[0, 16, 0], [0, 0, 16]]) c = np.array([[181, -420, 61]]) for vl in ((0, 1, 2, 3), (2, 7, 6, 3), (4, 5, 6, 7)): pt.addConvexPolygon(c + np.matmul(glyph[vl, :], T))