Werner's Miscellanea
Sign in or create your account | Project List | Help
Werner's Miscellanea Commit Details
Date: | 2011-07-23 16:16:02 (12 years 8 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 70eef566118ffe5f9be295f1038e431eced671b1 |
Message: | cad/test2/: copied original version of sources from cad/test1/ |
Files: |
cad/test2/Makefile (1 diff) cad/test2/button.py (4 diffs) cad/test2/button.scad (1 diff) |
Change Details
cad/test2/Makefile | ||
---|---|---|
1 | OUT=scad.stl cadmium.stl | |
2 | ||
3 | .PHONY: all clean | |
4 | ||
5 | all: $(OUT) | |
6 | ||
7 | scad.stl: button.scad | |
8 | time openscad -s $@ $< | |
9 | ||
10 | cadmium.stl: button.py | |
11 | time ./$< | |
12 | mv button.stl $@ | |
13 | ||
14 | clean: | |
15 | rm -f $(OUT) |
cad/test2/button.py | ||
---|---|---|
5 | 5 | from cadmium import * |
6 | 6 | |
7 | 7 | |
8 | epsilon = 0.01 | |
9 | noise = epsilon/10 | |
10 | ||
8 | 11 | but_top_x = 10.0 |
9 | 12 | but_top_y = but_top_x+5.0 |
10 | 13 | but_top_z = 1.5 |
... | ... | |
25 | 28 | |
26 | 29 | def fillet_line(x, r): |
27 | 30 | s = Box(x, r, r) |
28 | s -= Cylinder(r, h = x). \ | |
31 | s -= Cylinder(r, h = x+2*epsilon). \ | |
32 | translate(0, 0, -epsilon). \ | |
29 | 33 | rotate(Y_axis, 90). \ |
30 | 34 | translate(0, r, r) |
31 | 35 | return s.translate(-x/2, 0, 0) |
... | ... | |
40 | 44 | |
41 | 45 | |
42 | 46 | def chamfer_line (x, r): |
43 | s = Box(x, r, r) | |
44 | s -= Cylinder(r, h = x). \ | |
47 | s = Box(x, r+epsilon, r+epsilon) | |
48 | s -= Cylinder(r, h = x+2*epsilon). \ | |
49 | translate(0, 0, -epsilon). \ | |
45 | 50 | rotate(Y_axis, 90) |
46 | 51 | return s.translate(-x/2, -r, -r) |
47 | 52 | |
48 | 53 | def chamfer_circle(r, fillet_r): |
49 | return Box(2*(r), 2*(r), fillet_r). \ | |
50 | translate(-r, -r, -fillet_r)- \ | |
54 | return Box(2*(r+epsilon), 2*(r+epsilon), fillet_r+epsilon). \ | |
55 | translate(-r-epsilon, -r-epsilon, -fillet_r)- \ | |
51 | 56 | Cylinder(r-fillet_r, h = fillet_r). \ |
52 | 57 | translate(0, 0, -fillet_r)- \ |
53 | 58 | Torus(r-fillet_r, fillet_r, center = True). \ |
... | ... | |
98 | 103 | s = t |
99 | 104 | else: |
100 | 105 | s += t |
101 | return s-rbox_core(x, y, z, r) | |
106 | return s-rbox_core(x-epsilon, y-epsilon, z, r) | |
102 | 107 | |
103 | 108 | def rbox_chamfer_top(x, y, z, r, chamfer_r): |
104 | 109 | s = rbox_chamfer_top_corners(x, y, z, r, chamfer_r) |
105 | 110 | for a in [0, 180]: |
106 | 111 | s += chamfer_line(x-2*r, chamfer_r). \ |
107 | translate(0, y/2, z). \ | |
112 | translate(0, y/2, z+noise). \ | |
108 | 113 | rotate(Z_axis, a) |
109 | 114 | s += chamfer_line(y-2*r, chamfer_r). \ |
110 | translate(0, x/2, z). \ | |
115 | translate(0, x/2, z+noise). \ | |
111 | 116 | rotate(Z_axis, a+90) |
112 | 117 | return s |
113 | 118 |
cad/test2/button.scad | ||
---|---|---|
1 | epsilon = 0.01; | |
2 | ||
3 | but_top_x = 10; | |
4 | but_top_y = but_top_x+5; | |
5 | but_top_z = 1.5; | |
6 | ||
7 | but_corner_r = 2; | |
8 | ||
9 | but_base_border = 1; | |
10 | but_base_x = but_top_x+2*but_base_border; | |
11 | but_base_y = but_top_y+2*but_base_border; | |
12 | but_base_z = 0.5; | |
13 | ||
14 | but_push_r = 5; | |
15 | but_push_z = 0.5; | |
16 | ||
17 | but_fillet_r = 0.4; | |
18 | but_chamfer_r = 0.2; | |
19 | ||
20 | $fn = 40; | |
21 | ||
22 | ||
23 | /* ----- Basic solids ------------------------------------------------------ */ | |
24 | ||
25 | ||
26 | module torus(r0, r1) | |
27 | { | |
28 | rotate_extrude() | |
29 | translate([r0, 0, 0]) | |
30 | circle(r = r1); | |
31 | } | |
32 | ||
33 | ||
34 | /* ----- Helper elements for fillets --------------------------------------- */ | |
35 | ||
36 | ||
37 | module fillet_line(x, r) | |
38 | { | |
39 | translate([-x/2, 0, 0]) | |
40 | difference() { | |
41 | cube([x, r, r]); | |
42 | translate([0, r, r]) | |
43 | rotate([0, 90, 0]) | |
44 | translate([0, 0, -epsilon]) | |
45 | cylinder(h = x+2*epsilon, r = r); | |
46 | } | |
47 | } | |
48 | ||
49 | ||
50 | module fillet_circle(r, fillet_r) | |
51 | { | |
52 | difference() { | |
53 | cylinder(h = fillet_r, r = r+fillet_r); | |
54 | translate([0, 0, fillet_r]) | |
55 | torus(r+fillet_r, fillet_r); | |
56 | } | |
57 | } | |
58 | ||
59 | ||
60 | /* ----- Helper elements for chamfers -------------------------------------- */ | |
61 | ||
62 | ||
63 | module chamfer_line(x, r) | |
64 | { | |
65 | translate([-x/2, -r, -r]) | |
66 | difference() { | |
67 | cube([x, r+epsilon, r+epsilon]); | |
68 | rotate([0, 90, 0]) | |
69 | translate([0, 0, -epsilon]) | |
70 | cylinder(h = x+2*epsilon, r = r); | |
71 | } | |
72 | } | |
73 | ||
74 | ||
75 | module chamfer_circle(r, fillet_r) | |
76 | { | |
77 | difference() { | |
78 | translate([-r-epsilon, -r-epsilon, -fillet_r]) | |
79 | cube([2*(r+epsilon), 2*(r+epsilon), fillet_r+epsilon]); | |
80 | translate([0, 0, -fillet_r]) | |
81 | cylinder(h = fillet_r, r = r-fillet_r); | |
82 | translate([0, 0, -fillet_r]) | |
83 | torus(r-fillet_r, fillet_r); | |
84 | } | |
85 | } | |
86 | ||
87 | ||
88 | /* ----- Box with rounded corners ------------------------------------------ */ | |
89 | ||
90 | ||
91 | module rbox_core(x, y, z, r) | |
92 | { | |
93 | union() { | |
94 | translate([0, 0, z/2]) | |
95 | cube([x-2*r, y, z], center = true); | |
96 | translate([0, 0, z/2]) | |
97 | cube([x, y-2*r, z], center = true); | |
98 | } | |
99 | } | |
100 | ||
101 | ||
102 | module rbox(x, y, z, r) | |
103 | { | |
104 | union() { | |
105 | rbox_core(x, y, z, r); | |
106 | for (dx = [-1, 1]) { | |
107 | for (dy = [-1, 1]) { | |
108 | translate([dx*(x/2-r), dy*(y/2-r), 0]) | |
109 | cylinder(h = z, r = r); | |
110 | } | |
111 | } | |
112 | } | |
113 | } | |
114 | ||
115 | ||
116 | module rbox_fillet_bottom(x, y, z, r, fillet_r) | |
117 | { | |
118 | union() { | |
119 | for (a = [0, 180]) { | |
120 | rotate([0, 0, a]) | |
121 | translate([0, y/2, 0]) | |
122 | fillet_line(x-2*r, fillet_r); | |
123 | rotate([0, 0, a+90]) | |
124 | translate([0, x/2, 0]) | |
125 | fillet_line(y-2*r, fillet_r); | |
126 | } | |
127 | for (dx = [-1, 1]) { | |
128 | for (dy = [-1, 1]) { | |
129 | translate([dx*(x/2-r), dy*(y/2-r), 0]) | |
130 | fillet_circle(r, fillet_r); | |
131 | } | |
132 | } | |
133 | } | |
134 | } | |
135 | ||
136 | ||
137 | module rbox_chamfer_top_corners(x, y, z, r, chamfer_r) | |
138 | { | |
139 | difference() { | |
140 | union() { | |
141 | for (dx = [-1, 1]) { | |
142 | for (dy = [-1, 1]) { | |
143 | translate([dx*(x/2-r), dy*(y/2-r), z]) | |
144 | chamfer_circle(r, chamfer_r); | |
145 | } | |
146 | } | |
147 | } | |
148 | rbox_core(x-epsilon, y-epsilon, z, r); | |
149 | } | |
150 | } | |
151 | ||
152 | ||
153 | module rbox_chamfer_top(x, y, z, r, chamfer_r) | |
154 | { | |
155 | union() { | |
156 | for (a = [0, 180]) { | |
157 | rotate([0, 0, a]) | |
158 | translate([0, y/2, z]) | |
159 | chamfer_line(x-2*r, chamfer_r); | |
160 | rotate([0, 0, a+90]) | |
161 | translate([0, x/2, z]) | |
162 | chamfer_line(y-2*r, chamfer_r); | |
163 | } | |
164 | rbox_chamfer_top_corners(x, y, z, r, chamfer_r); | |
165 | } | |
166 | } | |
167 | ||
168 | ||
169 | module rbox_chamfer_bottom(x, y, z, r, chamfer_r) | |
170 | { | |
171 | rotate([180, 0, 0]) | |
172 | translate([0, 0, -z]) | |
173 | rbox_chamfer_top(x, y, z, r, chamfer_r); | |
174 | } | |
175 | ||
176 | ||
177 | /* ----- Button ------------------------------------------------------------ */ | |
178 | ||
179 | ||
180 | module button_top() | |
181 | { | |
182 | union() { | |
183 | difference() { | |
184 | rbox(but_top_x, but_top_y, but_top_z, but_corner_r); | |
185 | rbox_chamfer_top(but_top_x, but_top_y, but_top_z, but_corner_r, but_chamfer_r); | |
186 | } | |
187 | rbox_fillet_bottom(but_top_x, but_top_y, but_top_z, | |
188 | but_corner_r, but_fillet_r); | |
189 | } | |
190 | } | |
191 | ||
192 | ||
193 | module button_base() | |
194 | { | |
195 | translate([0, 0, -but_base_z]) | |
196 | difference() { | |
197 | rbox(but_base_x, but_base_y, but_base_z, but_corner_r); | |
198 | rbox_chamfer_top(but_base_x, but_base_y, but_base_z, | |
199 | but_corner_r, but_chamfer_r); | |
200 | rbox_chamfer_bottom(but_base_x, but_base_y, but_base_z, | |
201 | but_corner_r, but_chamfer_r); | |
202 | } | |
203 | } | |
204 | ||
205 | ||
206 | module button() | |
207 | { | |
208 | union() { | |
209 | button_top(); | |
210 | button_base(); | |
211 | // button_pusher(); | |
212 | } | |
213 | } | |
214 | ||
215 | ||
216 | button(); |
Branches:
master