# # slide.cad # # Charlie DeTar # HTMAA MIT 10/24/07 # # define shapes and transformation # # circle(x0, y0, r) # cylinder(x0, y0, z0, z1, r) # sphere(x0, y0, z0, r) # torus(x0, y0, z0, r0, r1) # rectangle(x0, x1, y0, y1) # cube(x0, x1, y0, y1, z0, z1) # function(Z_of_XY) # functions(upper_Z_of_XY,lower_Z_of_XY) # add(part1, part2) # subtract(part1, part2) # intersect(part1, part2) # move(part,dx,dy) # translate(part,dx,dy,dz) # rotate(part, angle) # rotate_x(part, angle) # rotate_y(part, angle) # rotate_z(part, angle) # rotate_z_90(part) # rotate_z_180(part) # rotate_z_270(part) # reflect_x(part) # reflect_y(part) # reflect_z(part) # reflect_xy(part) # reflect_xz(part) # reflect_yz(part) # scale_x(part, x0, sx) # scale_y(part, y0, sy) # scale_z(part, z0, sz) # scale_xy(part, x0, y0, sxy) # scale_xyz(part, x0, y0, z0, sxyz) # coscale_x_y(part, x0, y0, y1, angle0, angle1, amplitude, offset) # coscale_x_z(part, x0, z0, z1, angle0, angle1, amplitude, offset) # coscale_xy_z(part, x0, y0, z0, z1, angle0, angle1, amplitude, offset) # taper_x_y(part, x0, y0, y1, s0, s1) # taper_x_z(part, x0, z0, z1, s0, s1) # taper_xy_z(part, x0, y0, z0, z1, s0, s1) # shear_x_y(part, y0, y1, dx0, dx1) # shear_x_z(part, z0, z1, dx0, dx1) # (more to come) # coshear def circle(x0, y0, r): part = "(((X-x0)**2 + (Y-y0)**2) <= r**2)" part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'r',str(r)) return part def cylinder(x0, y0, z0, z1, r): part = "(((X-x0)**2 + (Y-y0)**2 <= r**2) & (Z >= z0) & (Z <= z1))" part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'r',str(r)) return part def sphere(x0, y0, z0, r): part = "(((X-x0)**2 + (Y-y0)**2 + (Z-z0)**2) <= r**2)" part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'r',str(r)) return part def torus(x0, y0, z0, r0, r1): part = "(((r0 - sqrt((X-x0)**2 + (Y-y0)**2))**2 + (Z-z0)**2) <= r1**2)" part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'r0',str(r0)) part = replace(part,'r1',str(r1)) return part def rectangle(x0, x1, y0, y1): part = "((X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1))" part = replace(part,'x0',str(x0)) part = replace(part,'x1',str(x1)) part = replace(part,'y0',str(y0)) part = replace(part,'y1',str(y1)) return part def cube(x0, x1, y0, y1, z0, z1): part = "((X >= x0) & (X <= x1) & (Y >= y0) & (Y <= y1) & (Z >= z0) & (Z <= z1))" part = replace(part,'x0',str(x0)) part = replace(part,'x1',str(x1)) part = replace(part,'y0',str(y0)) part = replace(part,'y1',str(y1)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) return part def function(Z_of_XY): part = '(Z <= '+Z_of_XY+')' return part def functions(upper_Z_of_XY,lower_Z_of_XY): part = '(Z <= '+upper_Z_of_XY+') & (Z >= '+lower_Z_of_XY+')' return part def add(part1, part2): part = "(part1) | (part2)" part = replace(part,'part1',part1) part = replace(part,'part2',part2) return part def subtract(part1, part2): part = "(part1) & ~(part2)" part = replace(part,'part1',part1) part = replace(part,'part2',part2) return part def intersect(part1, part2): part = "(part1) & (part2)" part = replace(part,'part1',part1) part = replace(part,'part2',part2) return part def move(part,dx,dy): part = replace(part,'X','(X-'+str(dx)+')') part = replace(part,'Y','(Y-'+str(dy)+')') return part def translate(part,dx,dy,dz): part = replace(part,'X','(X-'+str(dx)+')') part = replace(part,'Y','(Y-'+str(dy)+')') part = replace(part,'Z','(Z-'+str(dz)+')') return part def rotate(part, angle): angle = angle*pi/180 part = replace(part,'X','(cos(angle)*X+sin(angle)*y)') part = replace(part,'Y','(-sin(angle)*X+cos(angle)*y)') part = replace(part,'y','Y') part = replace(part,'angle',str(angle)) return part def rotate_x(part, angle): angle = angle*pi/180 part = replace(part,'Y','(cos(angle)*Y+sin(angle)*z)') part = replace(part,'Z','(-sin(angle)*Y+cos(angle)*z)') part = replace(part,'z','Z') part = replace(part,'angle',str(angle)) return part def rotate_y(part, angle): angle = angle*pi/180 part = replace(part,'X','(cos(angle)*X+sin(angle)*z)') part = replace(part,'Z','(-sin(angle)*X+cos(angle)*z)') part = replace(part,'z','Z') part = replace(part,'angle',str(angle)) return part def rotate_z(part, angle): angle = angle*pi/180 part = replace(part,'X','(cos(angle)*X+sin(angle)*y)') part = replace(part,'Y','(-sin(angle)*X+cos(angle)*y)') part = replace(part,'y','Y') part = replace(part,'angle',str(angle)) return part def rotate_z_90(part): part = reflect_xy(part) part = reflect_y(part) return part def rotate_z_180(part): part = reflect_xy(part) part = reflect_y(part) part = reflect_xy(part) part = reflect_y(part) return part def rotate_z_270(part): part = reflect_xy(part) part = reflect_y(part) part = reflect_xy(part) part = reflect_y(part) part = reflect_xy(part) part = reflect_y(part) return part def reflect_x(part): part = replace(part,'X','-X') return part def reflect_y(part): part = replace(part,'Y','-Y') return part def reflect_z(part): part = replace(part,'Z','-Z') return part def reflect_xy(part): part = replace(part,'X','temp') part = replace(part,'Y','X') part = replace(part,'temp','Y') return part def reflect_xz(part): part = replace(part,'X','temp') part = replace(part,'Z','X') part = replace(part,'temp','Z') return part def reflect_yz(part): part = replace(part,'Y','temp') part = replace(part,'Z','Y') part = replace(part,'temp','Z') return part def scale_x(part, x0, sx): part = replace(part,'X','(x0 + (X-x0)/sx)') part = replace(part,'x0',str(x0)) part = replace(part,'sx',str(sx)) return part def scale_y(part, y0, sy): part = replace(part,'Y','(y0 + (Y-y0)/sy)') part = replace(part,'y0',str(y0)) part = replace(part,'sy',str(sy)) return part def scale_z(part, z0, sz): part = replace(part,'Z','(z0 + (Z-z0)/sz)') part = replace(part,'z0',str(z0)) part = replace(part,'sz',str(sz)) return part def scale_xy(part, x0, y0, sxy): part = replace(part,'X','(x0 + (X-x0)/sx)') part = replace(part,'Y','(y0 + (Y-y0)/sy)') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'sxy',str(sxy)) return part def scale_xyz(part, x0, y0, z0, sxy): part = replace(part,'X','(x0 + (X-x0)/sx)') part = replace(part,'Y','(y0 + (Y-y0)/sy)') part = replace(part,'Z','(z0 + (Z-z0)/sz)') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'sxyz',str(sxyz)) return part def coscale_x_y(part, x0, y0, y1, angle0, angle1, amplitude, offset): phase0 = pi*angle0/180. phase1 = pi*angle1/180. part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Y-y0)/(y1-y0))))') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'y1',str(y1)) part = replace(part,'phase0',str(phase0)) part = replace(part,'phase1',str(phase1)) part = replace(part,'amplitude',str(amplitude)) part = replace(part,'offset',str(offset)) return part def coscale_x_z(part, x0, z0, z1, angle0, angle1, amplitude, offset): phase0 = pi*angle0/180. phase1 = pi*angle1/180. part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))') part = replace(part,'x0',str(x0)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'phase0',str(phase0)) part = replace(part,'phase1',str(phase1)) part = replace(part,'amplitude',str(amplitude)) part = replace(part,'offset',str(offset)) return part def coscale_xy_z(part, x0, y0, z0, z1, angle0, angle1, amplitude, offset): phase0 = pi*angle0/180. phase1 = pi*angle1/180. part = replace(part,'X','(x0 + (X-x0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))') part = replace(part,'Y','(y0 + (Y-y0)/(offset + amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0))))') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'phase0',str(phase0)) part = replace(part,'phase1',str(phase1)) part = replace(part,'amplitude',str(amplitude)) part = replace(part,'offset',str(offset)) return part def taper_x_y(part, x0, y0, y1, s0, s1): part = replace(part,'X','(x0 + (X-x0)*(y1-y0)/(s1*(Y-y0) + s0*(y1-Y)))') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'y1',str(y1)) part = replace(part,'s0',str(s0)) part = replace(part,'s1',str(s1)) return part def taper_x_z(part, x0, z0, z1, s0, s1): part = replace(part,'X','(x0 + (X-x0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))') part = replace(part,'x0',str(x0)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'s0',str(s0)) part = replace(part,'s1',str(s1)) return part def taper_xy_z(part, x0, y0, z0, z1, s0, s1): part = replace(part,'X','(x0 + (X-x0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))') part = replace(part,'Y','(y0 + (Y-y0)*(z1-z0)/(s1*(Z-z0) + s0*(z1-Z)))') part = replace(part,'x0',str(x0)) part = replace(part,'y0',str(y0)) part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'s0',str(s0)) part = replace(part,'s1',str(s1)) return part def shear_x_y(part, y0, y1, dx0, dx1): part = replace(part,'X','(X - dx0 - (dx1-dx0)*(Y-y0)/(y1-y0))') part = replace(part,'y0',str(y0)) part = replace(part,'y1',str(y1)) part = replace(part,'dx0',str(dx0)) part = replace(part,'dx1',str(dx1)) return part def shear_x_z(part, z0, z1, dx0, dx1): part = replace(part,'X','(X - dx0 - (dx1-dx0)*(Z-z0)/(z1-z0))') part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'dx0',str(dx0)) part = replace(part,'dx1',str(dx1)) return part def coshear_x_z(part, z0, z1, angle0, angle1, amplitude, offset): phase0 = pi*angle0/180. phase1 = pi*angle1/180. part = replace(part,'X','(X - offset - amplitude*cos(phase0 + (phase1-phase0)*(Z-z0)/(z1-z0)))') part = replace(part,'z0',str(z0)) part = replace(part,'z1',str(z1)) part = replace(part,'phase0',str(phase0)) part = replace(part,'phase1',str(phase1)) part = replace(part,'amplitude',str(amplitude)) part = replace(part,'offset',str(offset)) return part # # define part # in_d = 11/16. # inside diameter taper = 1/8. # inner taper amount, from bottom to top thickness = 0.125 # minimum outside thickness out_d = in_d + thickness * 2 # outside diameter length = 1.75 # e.g., height cutaway_angle = 45 # angle of knuckle notch infinity = 2.0 # value outside of all above dims mold_bevel = 0.1 # make slide part... outside = cylinder(0, 0, -length / 2, length / 2, out_d / 2) inside = cylinder(0, 0, -length / 2, length / 2, in_d / 2) #inside = taper_xy_z(inside, 0, 0, -length/2, length/2, in_d, in_d + taper) slide = subtract(outside, inside) cutaway = cube(-infinity, infinity, -infinity, 0, 0, infinity) cutaway = rotate_x(cutaway, cutaway_angle) cutaway = translate(cutaway, 0, 0, length/2) slide = subtract(slide, cutaway) slide = translate(slide, 0, 0, -length/2) # make upper mold upper_mold = 'True' w = out_d / 2 + 0.26 # width of mold cube iw = w - 0.13 # interior bevel of mold cube ow = w + 0.25 # exterior bevel of mold cube z_part = length * 0.4 # portion of slide to use in upper mold vent_h = 0.2 # length of vents wstep = 0.05 # width of anti bit-bind steps hstep = 0.25 # height of anti bit-bind steps # cutaway cube to put things in. But step it, so we don't bind the bit at the corners. h = -z_part - mold_bevel - vent_h r = w while h < 0: upper_mold = subtract(upper_mold, cylinder(0, 0, h, infinity, r)) r += wstep h += hstep # add a pedastel for the slide upper_mold = add(upper_mold, cylinder(0, 0, -z_part - mold_bevel - vent_h, -z_part - vent_h, iw)) # add the slide. upper_mold = add(upper_mold, translate(slide, 0, 0, -vent_h)) # add vents vent = cylinder(0, 0, -infinity, infinity, thickness / 2.) r = (in_d + thickness) / 2 upper_mold = add(upper_mold, translate(vent, r, 0, 0)) upper_mold = add(upper_mold, translate(vent, -r, 0, 0)) # make lower mold lower_mold = 'True' # get the rest of the length of the part that we haven't used z_remain = length - z_part # deep cut to put part in lower_mold = subtract(lower_mold, cylinder(0, 0, -z_remain, 0, iw)) # bevel to mate with upper mold, then stepping out. cheat above 0 for render. h = -z_remain + mold_bevel r = w while h < 0: lower_mold = subtract(lower_mold, cylinder(0, 0, h, infinity, r)) h += hstep r += wstep upside_down_slide = translate(rotate_z_180(translate(slide, 0, 0, length/2)), 0, 0, -length/2) lower_mold = add(lower_mold, translate(slide, 0, 0, length - z_remain)) part = slide #part = upper_mold part = lower_mold # additional cutaway for visibility - comment out before fabbing #part = subtract(part, cube(0, infinity, -infinity, 0, -infinity, infinity)) # move us to 1/1 for rendering part = translate(part, infinity/2 + 1, infinity/2 + 1, 0) # # define limits and parameters # cad.xmin = 1 cad.xmax = 1 + infinity cad.ymin = 1 cad.ymax = 1 + infinity cad.zmin = -1.25 # thickness of wax block #cad.zmin = -1.1 cad.zmax = 0 cad.rx = 20 # x view rotation (degrees) cad.rz = 20 # z view rotation (degrees) dpi = 50 # low resolution for previewing dpi = 250 # high resolution for machining nxy = int(dpi*(cad.xmax-cad.xmin)) cad.nx = nxy cad.ny = nxy dz = 0.025 cad.nz = int((cad.zmax-cad.zmin)/dz) cad.inches_per_unit = 1.0 # use inch units # # assign part to cad.function # cad.function = part