def test_split_body_planar(self): offset = [10, 10, 10] body = translate(offset)(sphere(20)) body_bb = BoundingBox([40, 40, 40], offset) actual = [] for split_dir in [RIGHT_VEC, FORWARD_VEC, UP_VEC]: actual_tuple = split_body_planar(body, body_bb, cutting_plane_normal=split_dir, cut_proportion=0.25) actual.append(actual_tuple) # Ignore the bounding box object that come back, taking only the SCAD # objects actual = [scad_render(a) for splits in actual for a in splits[::2]] expected = [ '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [-5.0000000000, 10, 10]) {\n\t\tcube(center = true, size = [10.0000000000, 40, 40]);\n\t}\n}', '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [15.0000000000, 10, 10]) {\n\t\tcube(center = true, size = [30.0000000000, 40, 40]);\n\t}\n}', '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, -5.0000000000, 10]) {\n\t\tcube(center = true, size = [40, 10.0000000000, 40]);\n\t}\n}', '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 15.0000000000, 10]) {\n\t\tcube(center = true, size = [40, 30.0000000000, 40]);\n\t}\n}', '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 10, -5.0000000000]) {\n\t\tcube(center = true, size = [40, 40, 10.0000000000]);\n\t}\n}', '\n\nintersection() {\n\ttranslate(v = [10, 10, 10]) {\n\t\tsphere(r = 20);\n\t}\n\ttranslate(v = [10, 10, 15.0000000000]) {\n\t\tcube(center = true, size = [40, 40, 30.0000000000]);\n\t}\n}' ] self.assertEqual(actual, expected)
def bottom_part(): top = difference() u = union() u2 = union() top.add(u) d = difference() d.add(cylinder(r=innerR + wall + gap, h=toph)) d.add(translate((0, 0, baseH)).add(cylinder(r=innerR + gap, h=toph))) u.add(d) top.add(u2) for i in range(0, 3): a = i * 2 * pi / 3 r = innerR + gap + wall / 2 u.add( translate(((r - 0.3) * cos(a), (r - 0.3) * sin(a), toph - 6)).add(sphere(r=2.4))) u2.add( translate(((r + wall - 0.3) * cos(a), (r + wall - 0.3) * sin(a), toph - 6)).add(sphere(r=2.4))) return top
def test_infix_intersection(self): a = cube(2) b = sphere(2) expected = '\n\nintersection() {\n\tcube(size = 2);\n\tsphere(r = 2);\n}' actual = scad_render(a * b) self.assertEqual(expected, actual)
def test_infix_difference(self): a = cube(2) b = sphere(2) expected = '\n\ndifference() {\n\tcube(size = 2);\n\tsphere(r = 2);\n}' actual = scad_render(a - b) self.assertEqual(expected, actual)
def ostov53(z, angle, nuc): element = (union()( color("Gainsboro")(translate([radius, 0, 0])(sphere(8))), color("Gainsboro")(translate([radius, 15, 0])(sphere(8))), color("Gainsboro")(translate([radius, 20, 15])(sphere(8))), color("Gainsboro")(translate([radius, -5, 15])(sphere(8))), color("Gainsboro")(translate([radius, 7.5, 25])(sphere(10))), color("Gainsboro")(translate([radius, -15, 25])(sphere(8))), color("Yellow")(translate([radius, -20, 42.5])(sphere(10))), color("Yellow")(translate([radius, -20, 60])(sphere(13))), color("Yellow")(translate([radius, -20, 80])(sphere(10))), color("Yellow")(translate([radius, -40, 60])(sphere(10))), color("Yellow")(translate([radius, 0, 60])(sphere(10))))) element1 = translate([0, 0, z])(rotate(angle)(element)) element2 = translate([0, 0, z])(rotate(angle)( (translate([0, 0, 80])(rotate(a=[0, 180, 0])(element))))) if nuc == "A": # nuc2="T" nucleus1 = rotate(angle)(translate([radius / 2, 0, z + 20])( (translate([0, 30, 0])(rotate(150)(union()( color("Green")(translate([0, 0, 0])(sphere(9))), color("Blue")(translate([-10, 7.5, 0])(sphere(8))), color("Green")(translate([-20, 8, 0])(sphere(9))), color("Blue")(translate([-30, 15, 0])(sphere(8))), color("Green")(translate([-20, 26, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Green")(translate([10, 22.5, 0])(sphere(9))), color("Blue")(translate([10, 7.5, 0])(sphere(8))), color("Green")(translate([0, 44, 0])(sphere(9))), color("Gray")(translate([0, 54, 0])(sphere(4))), color("Gray")(translate([10, 44, 0])(sphere(4))), )))))) nucleus2 = rotate(angle + 180)(translate([radius / 1.7, 0, z + 20])( translate([0, 10, 0])(rotate(25)((union()( color("Blue")(translate([0, 0, 0])(sphere(8))), color("Green")(translate([-10, 7.5, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Blue")(translate([10, 22.5, 0])(sphere(8))), color("Green")(translate([10, 7.5, 0])(sphere(9))), color("Red")(translate([0, -14, 0])(sphere(10))), color("Red")(translate([-24, 25, 0])(sphere(10))), color("Gray")(translate([-20, 7.5, 0])(sphere(4))), )))))) elif nuc == "G": # nuc2="C" nucleus1 = rotate(angle)(translate([radius / 2.5, 0, z + 20])( translate([0, 20, 0])(rotate(170)((union()( color("Green")(translate([0, 0, 0])(sphere(9))), color("Blue")(translate([-10, 7.5, 0])(sphere(8))), color("Green")(translate([-20, 4, 0])(sphere(9))), color("Blue")(translate([-30, 15, 0])(sphere(8))), color("Green")(translate([-20, 26, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Green")(translate([10, 22.5, 0])(sphere(9))), color("Blue")(translate([10, 7.5, 0])(sphere(8))), color("Green")(translate([20, 0, 0])(sphere(9))), color("Gray")(translate([20, -10, 0])(sphere(4))), color("Gray")(translate([30, 0, 0])(sphere(4))), color("Red")(translate([0, 46, 0])(sphere(10))), color("Gray")(translate([20, 22.5, 0])(sphere(4))), )))))) nucleus2 = rotate(angle + 180)(translate([radius / 2, 0, z + 20])( translate([0, 10, 0])(rotate(0)((union()( color("Blue")(translate([0, 0, 0])(sphere(8))), color("Green")(translate([-10, 7.5, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Blue")(translate([10, 22.5, 0])(sphere(8))), color("Green")(translate([10, 7.5, 0])(sphere(9))), color("Red")(translate([0, -14, 0])(sphere(10))), color("Green")(translate([-24, 25, 0])(sphere(9))), color("Gray")(translate([-24, 35, 0])(sphere(4))), color("Gray")(translate([-34, 25, 0])(sphere(4))), )))))) elif nuc == "C": # nuc2="G" nucleus1 = rotate(angle)(translate([radius / 2, 0, z + 20])(translate( [0, 5, 0])(rotate(5)((union()( color("Blue")(translate([0, 0, 0])(sphere(8))), color("Green")(translate([-10, 7.5, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Blue")(translate([10, 22.5, 0])(sphere(8))), color("Green")(translate([10, 7.5, 0])(sphere(9))), color("Red")(translate([0, -14, 0])(sphere(10))), color("Green")(translate([-24, 25, 0])(sphere(9))), color("Gray")(translate([-24, 35, 0])(sphere(4))), color("Gray")(translate([-34, 25, 0])(sphere(4))), )))))) nucleus2 = rotate(angle + 180)(translate([radius / 2, 0, z + 20])( translate([0, 20, 0])(rotate(160)((union()( color("Green")(translate([0, 0, 0])(sphere(9))), color("Blue")(translate([-10, 7.5, 0])(sphere(8))), color("Green")(translate([-20, 4, 0])(sphere(9))), color("Blue")(translate([-30, 15, 0])(sphere(8))), color("Green")(translate([-20, 26, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Green")(translate([10, 22.5, 0])(sphere(9))), color("Blue")(translate([10, 7.5, 0])(sphere(8))), color("Green")(translate([20, 0, 0])(sphere(9))), color("Gray")(translate([20, -10, 0])(sphere(4))), color("Gray")(translate([30, 0, 0])(sphere(4))), color("Red")(translate([0, 46, 0])(sphere(10))), color("Gray")(translate([20, 22.5, 0])(sphere(4))), )))))) elif nuc == "T": # nuc2="A" nucleus1 = rotate(angle)(translate([radius / 1.6, 0, z + 20])( translate([0, 0, 0])(rotate(30)((union()( color("Blue")(translate([0, 0, 0])(sphere(8))), color("Green")(translate([-10, 7.5, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Blue")(translate([10, 22.5, 0])(sphere(8))), color("Green")(translate([10, 7.5, 0])(sphere(9))), color("Red")(translate([0, -14, 0])(sphere(10))), color("Red")(translate([-24, 25, 0])(sphere(10))), color("Gray")(translate([-20, 7.5, 0])(sphere(4))), )))))) nucleus2 = rotate(angle + 180)(translate([radius / 1.7, 0, z + 20])( (translate([0, 30, 0])(rotate(137)(union()( color("Green")(translate([0, 0, 0])(sphere(9))), color("Blue")(translate([-10, 7.5, 0])(sphere(8))), color("Green")(translate([-20, 8, 0])(sphere(9))), color("Blue")(translate([-30, 15, 0])(sphere(8))), color("Green")(translate([-20, 26, 0])(sphere(9))), color("Blue")(translate([-10, 22.5, 0])(sphere(8))), color("Blue")(translate([0, 30, 0])(sphere(8))), color("Green")(translate([10, 22.5, 0])(sphere(9))), color("Blue")(translate([10, 7.5, 0])(sphere(8))), color("Green")(translate([0, 44, 0])(sphere(9))), color("Gray")(translate([0, 54, 0])(sphere(4))), color("Gray")(translate([10, 44, 0])(sphere(4))), )))))) return element1 + element2 + nucleus1 + nucleus2