from koko.lib.shapes import * side = 3.75 # cm, length of cube side inner_side = 1.25 #cm, length of side of inner square thickness = .65 # cm, thickness of wall magd = 0.635 # cm, diameter of magnet mag_cutd = thickness/4 cad.mm_per_unit = 10 # 10mm per cm #====================== #Make the surface #====================== #Some calcs to simplify things in writing shape equations s_d = (side-inner_side)/2 sqrt2=math.sqrt(2) offset = thickness hole_offset = inner_side/2 # Making all the triangles for the surface t1 = move(triangle(0,0,s_d,s_d,s_d,0),offset,0) t2 = move(triangle(0,0,s_d,s_d,s_d,0),side-s_d,side-offset-s_d) t3 = move(triangle(0,0,0,s_d,s_d,0),side-offset-s_d,0) t4 = move(triangle(0,0,0,s_d,s_d,0),0,side-offset-s_d) t5 = move(triangle(0,0,0,s_d,s_d,s_d),0,offset) t6 = move(triangle(0,0,0,s_d,s_d,s_d),side-offset-s_d,side-s_d) t7 = move(triangle(0,s_d,s_d,s_d,s_d,0),offset,side-s_d) t8 = move(triangle(0,s_d,s_d,s_d,s_d,0),side-s_d,offset) # Making all the rectangles for the surface r = rectangle(0,side-2*offset-2*s_d,0,s_d) r1 = move(r,offset+s_d,0) r2 = move(r,offset+s_d,side-s_d) r3 = move(reflect_x(rotate(r,90)),0,offset+s_d) r4 = move(reflect_x(rotate(r,90)),side-s_d,offset+s_d) # Small holes so you can see magnet hole1 = circle(hole_offset,hole_offset,magd/4.0) hole2 = move(hole1,0,-2.0*hole_offset) hole3 = reflect_x(hole1) hole4 = reflect_x(hole2) holes = move(hole1+hole2+hole3+hole4,side/2.0,side/2.0) # Make surface side_surf = rectangle(0,side,0,side)-(t1+t2+t3+t4+t5+t6+t7+t8+r1+r2+r3+r4+holes) #====================== #Make the bottom part #====================== # Make cut for magnet press fit hole1a = circle(hole_offset,hole_offset,magd/2) hole2a = reflect_y(hole1a) hole3a = reflect_x(hole1a) hole4a = reflect_x(hole2a) holesa = move(hole1a+hole2a+hole3a+hole4a,side/2.0,side/2.0) mag_cut = move(extrusion(holesa,0,thickness),0,0,mag_cutd) bottom = extrusion(side_surf,0,offset) - mag_cut #====================== # Mirror to the other sides #====================== top = move(rotate_x(bottom,180),0,side,side) sidea = move(rotate_y(bottom,270),0,0,side) sideb = move(rotate_y(bottom,90),side,0) sidec = move(rotate_x(bottom,270),0,0,side) sided = move(move(rotate_x(bottom,90),0,thickness),0,side-thickness) cad.shapes = bottom,sidea,sideb,top,sidec,sided,