def create_piece(piece, mirror): bit_diameter = 0.125 corner_radius = 0.1875 groove_depth = 0.0625 cells = [cell(x, y) for x, y in piece] mp = cascaded_union(cells).buffer(-corner_radius).buffer(corner_radius) g = GCode() for p in cells: g += GCode.from_geometry(p, G0Z, -groove_depth) g += GCode.from_geometry(mp.buffer(bit_diameter / 2), G0Z, -0.4, bit_diameter + 0.2, 3.5) if mirror: g = g.scale(-1, 1) g = g.origin() return g
def create_shape(sides, length): p = create_points(sides, length) g = GCode() g += GCode.from_points(p, G0Z, -0.24) # g += GCode.from_points(p, G0Z, -0.4) # g += GCode.from_points(p, G0Z, -0.5) # g = g.rotate_and_scale_to_fit(6.5, 8) # g = g.rotate(180) g = g + g.translate(0, 4) g = g.origin() g = HEADER + g + FOOTER g.save('solids.nc') im = g.render(0, 0, 6.5, 8, 96) im.write_to_png('solids.png')
def main(): bit = 0.125 r = 0.21875 d = 0.09375 steps = 16 cells = [ cell(0, 0), cell(1, 0), cell(1, 1), cell(2, 1), cell(3, 1), ] mp = cascaded_union(cells).buffer(-bit).buffer(bit) g = GCode() for p in cells: g += GCode.from_geometry(p, G0Z, -d) # for p in cells: # g += GCode.from_geometry(p, G0Z, -bit) for step in range(steps): p = step / (steps - 1.0) a = radians(p * 90) x = sin(a) * r b = x + bit / 2 - r z = r - (r * r - x * x) ** 0.5 print '%.3f, %.3f, %.3f, %.3f' % (p, x, b, z) g += GCode.from_geometry(mp.buffer(b), G0Z, -z) # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.4) # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.7) # g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.6, bit + 0.1, 3) g += GCode.from_geometry(mp.buffer(bit / 2), G0Z, -0.4, bit + 0.2, 3.5) g = g.scale(-1, 1) g = g.origin().translate(0, 0.5) g = HEADER + g + FOOTER p = 0#0.5 im = g.render(-p, -p, 6 + p, 6 + p, 96*4) im.write_to_png('blokus.png') g.save('blokus.nc')
def create_face(dihedral, sides, length, depth, iterations): angle = radians((180 - dihedral) / 2) hyp = 1 / cos(angle) * depth max_offset = sin(angle) * hyp points = [] for i in range(iterations): p = i / float(iterations - 1) offset = sin(angle) * p * hyp z = -cos(angle) * p * hyp p = create_points(sides, length, offset - max_offset) p = [(x, y, z) for x, y in p] points.extend(p) lines = [] lines.append('G0 Z%f' % G0Z) lines.append('G0 X%f Y%f' % points[0][:2]) for point in points: lines.append('G1 X%f Y%f Z%f' % point) lines.append('G0 Z%f' % G0Z) g = GCode(lines) g = g.origin() g = HEADER + g + FOOTER g.save('polyhedra.nc') im = g.render(0, 0, 6, 8, 96) im.write_to_png('polyhedra.png')