From 70eef566118ffe5f9be295f1038e431eced671b1 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 23 Jul 2011 11:16:02 -0300 Subject: [PATCH] cad/test2/: copied original version of sources from cad/test1/ --- cad/test2/Makefile | 15 +++ cad/test2/button.py | 21 ++-- cad/test2/button.scad | 216 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 244 insertions(+), 8 deletions(-) create mode 100644 cad/test2/Makefile create mode 100644 cad/test2/button.scad diff --git a/cad/test2/Makefile b/cad/test2/Makefile new file mode 100644 index 0000000..38e3efc --- /dev/null +++ b/cad/test2/Makefile @@ -0,0 +1,15 @@ +OUT=scad.stl cadmium.stl + +.PHONY: all clean + +all: $(OUT) + +scad.stl: button.scad + time openscad -s $@ $< + +cadmium.stl: button.py + time ./$< + mv button.stl $@ + +clean: + rm -f $(OUT) diff --git a/cad/test2/button.py b/cad/test2/button.py index dc07fa2..7e58864 100755 --- a/cad/test2/button.py +++ b/cad/test2/button.py @@ -5,6 +5,9 @@ from cadmium import * +epsilon = 0.01 +noise = epsilon/10 + but_top_x = 10.0 but_top_y = but_top_x+5.0 but_top_z = 1.5 @@ -25,7 +28,8 @@ but_chamfer_r = 0.2 def fillet_line(x, r): s = Box(x, r, r) - s -= Cylinder(r, h = x). \ + s -= Cylinder(r, h = x+2*epsilon). \ + translate(0, 0, -epsilon). \ rotate(Y_axis, 90). \ translate(0, r, r) return s.translate(-x/2, 0, 0) @@ -40,14 +44,15 @@ def fillet_circle(r, fillet_r): def chamfer_line (x, r): - s = Box(x, r, r) - s -= Cylinder(r, h = x). \ + s = Box(x, r+epsilon, r+epsilon) + s -= Cylinder(r, h = x+2*epsilon). \ + translate(0, 0, -epsilon). \ rotate(Y_axis, 90) return s.translate(-x/2, -r, -r) def chamfer_circle(r, fillet_r): - return Box(2*(r), 2*(r), fillet_r). \ - translate(-r, -r, -fillet_r)- \ + return Box(2*(r+epsilon), 2*(r+epsilon), fillet_r+epsilon). \ + translate(-r-epsilon, -r-epsilon, -fillet_r)- \ Cylinder(r-fillet_r, h = fillet_r). \ translate(0, 0, -fillet_r)- \ Torus(r-fillet_r, fillet_r, center = True). \ @@ -98,16 +103,16 @@ def rbox_chamfer_top_corners(x, y, z, r, chamfer_r): s = t else: s += t - return s-rbox_core(x, y, z, r) + return s-rbox_core(x-epsilon, y-epsilon, z, r) def rbox_chamfer_top(x, y, z, r, chamfer_r): s = rbox_chamfer_top_corners(x, y, z, r, chamfer_r) for a in [0, 180]: s += chamfer_line(x-2*r, chamfer_r). \ - translate(0, y/2, z). \ + translate(0, y/2, z+noise). \ rotate(Z_axis, a) s += chamfer_line(y-2*r, chamfer_r). \ - translate(0, x/2, z). \ + translate(0, x/2, z+noise). \ rotate(Z_axis, a+90) return s diff --git a/cad/test2/button.scad b/cad/test2/button.scad new file mode 100644 index 0000000..f5fc7bb --- /dev/null +++ b/cad/test2/button.scad @@ -0,0 +1,216 @@ +epsilon = 0.01; + +but_top_x = 10; +but_top_y = but_top_x+5; +but_top_z = 1.5; + +but_corner_r = 2; + +but_base_border = 1; +but_base_x = but_top_x+2*but_base_border; +but_base_y = but_top_y+2*but_base_border; +but_base_z = 0.5; + +but_push_r = 5; +but_push_z = 0.5; + +but_fillet_r = 0.4; +but_chamfer_r = 0.2; + +$fn = 40; + + +/* ----- Basic solids ------------------------------------------------------ */ + + +module torus(r0, r1) +{ + rotate_extrude() + translate([r0, 0, 0]) + circle(r = r1); +} + + +/* ----- Helper elements for fillets --------------------------------------- */ + + +module fillet_line(x, r) +{ + translate([-x/2, 0, 0]) + difference() { + cube([x, r, r]); + translate([0, r, r]) + rotate([0, 90, 0]) + translate([0, 0, -epsilon]) + cylinder(h = x+2*epsilon, r = r); + } +} + + +module fillet_circle(r, fillet_r) +{ + difference() { + cylinder(h = fillet_r, r = r+fillet_r); + translate([0, 0, fillet_r]) + torus(r+fillet_r, fillet_r); + } +} + + +/* ----- Helper elements for chamfers -------------------------------------- */ + + +module chamfer_line(x, r) +{ + translate([-x/2, -r, -r]) + difference() { + cube([x, r+epsilon, r+epsilon]); + rotate([0, 90, 0]) + translate([0, 0, -epsilon]) + cylinder(h = x+2*epsilon, r = r); + } +} + + +module chamfer_circle(r, fillet_r) +{ + difference() { + translate([-r-epsilon, -r-epsilon, -fillet_r]) + cube([2*(r+epsilon), 2*(r+epsilon), fillet_r+epsilon]); + translate([0, 0, -fillet_r]) + cylinder(h = fillet_r, r = r-fillet_r); + translate([0, 0, -fillet_r]) + torus(r-fillet_r, fillet_r); + } +} + + +/* ----- Box with rounded corners ------------------------------------------ */ + + +module rbox_core(x, y, z, r) +{ + union() { + translate([0, 0, z/2]) + cube([x-2*r, y, z], center = true); + translate([0, 0, z/2]) + cube([x, y-2*r, z], center = true); + } +} + + +module rbox(x, y, z, r) +{ + union() { + rbox_core(x, y, z, r); + for (dx = [-1, 1]) { + for (dy = [-1, 1]) { + translate([dx*(x/2-r), dy*(y/2-r), 0]) + cylinder(h = z, r = r); + } + } + } +} + + +module rbox_fillet_bottom(x, y, z, r, fillet_r) +{ + union() { + for (a = [0, 180]) { + rotate([0, 0, a]) + translate([0, y/2, 0]) + fillet_line(x-2*r, fillet_r); + rotate([0, 0, a+90]) + translate([0, x/2, 0]) + fillet_line(y-2*r, fillet_r); + } + for (dx = [-1, 1]) { + for (dy = [-1, 1]) { + translate([dx*(x/2-r), dy*(y/2-r), 0]) + fillet_circle(r, fillet_r); + } + } + } +} + + +module rbox_chamfer_top_corners(x, y, z, r, chamfer_r) +{ + difference() { + union() { + for (dx = [-1, 1]) { + for (dy = [-1, 1]) { + translate([dx*(x/2-r), dy*(y/2-r), z]) + chamfer_circle(r, chamfer_r); + } + } + } + rbox_core(x-epsilon, y-epsilon, z, r); + } +} + + +module rbox_chamfer_top(x, y, z, r, chamfer_r) +{ + union() { + for (a = [0, 180]) { + rotate([0, 0, a]) + translate([0, y/2, z]) + chamfer_line(x-2*r, chamfer_r); + rotate([0, 0, a+90]) + translate([0, x/2, z]) + chamfer_line(y-2*r, chamfer_r); + } + rbox_chamfer_top_corners(x, y, z, r, chamfer_r); + } +} + + +module rbox_chamfer_bottom(x, y, z, r, chamfer_r) +{ + rotate([180, 0, 0]) + translate([0, 0, -z]) + rbox_chamfer_top(x, y, z, r, chamfer_r); +} + + +/* ----- Button ------------------------------------------------------------ */ + + +module button_top() +{ + union() { + difference() { + rbox(but_top_x, but_top_y, but_top_z, but_corner_r); + rbox_chamfer_top(but_top_x, but_top_y, but_top_z, but_corner_r, but_chamfer_r); + } + rbox_fillet_bottom(but_top_x, but_top_y, but_top_z, + but_corner_r, but_fillet_r); + } +} + + +module button_base() +{ + translate([0, 0, -but_base_z]) + difference() { + rbox(but_base_x, but_base_y, but_base_z, but_corner_r); + rbox_chamfer_top(but_base_x, but_base_y, but_base_z, + but_corner_r, but_chamfer_r); + rbox_chamfer_bottom(but_base_x, but_base_y, but_base_z, + but_corner_r, but_chamfer_r); + } +} + + +module button() +{ + union() { + button_top(); + button_base(); +// button_pusher(); + } +} + + +button();