|
0
|
1 // hinged box with filament hinge at the back and a hinged latch in front.
|
|
|
2 // sized by its inner dimensions, e.g. for standing notepad paper.
|
|
|
3 // x runs front (-x) to back (+x), y left to right, z up.
|
|
|
4
|
|
|
5 /* [part selection] */
|
|
|
6 // part to show or export
|
|
|
7 part = "all"; // [all, body, lid, latch]
|
|
|
8 // cut away the -y half in preview
|
|
1
|
9 preview_cut = false;
|
|
0
|
10 // show a paper stack mockup in the assembly view
|
|
|
11 preview_paper = false;
|
|
|
12 // show the filament pins and latch bar in the assembly view
|
|
|
13 preview_hardware = false;
|
|
|
14 // lid opening angle in the assembly view
|
|
|
15 preview_lid_angle = 0; // [0:1:180]
|
|
|
16 // latch opening angle in the assembly view
|
|
|
17 preview_latch_angle = 0; // [0:1:75]
|
|
|
18
|
|
|
19 /* [box] */
|
|
|
20 // inner size front to back
|
|
|
21 inner_depth = 92; // [10:1:300]
|
|
|
22 // inner size left to right, the thickness of the paper stack
|
|
|
23 inner_width = 92; // [10:1:300]
|
|
|
24 // inner height, floor to lid ceiling
|
|
|
25 inner_height = 92; // [10:1:300]
|
|
|
26 // share of the inner height taken by the body
|
|
2
|
27 body_ratio = .85; // [.1:.01:.99]
|
|
0
|
28 // radius of the vertical outer edges
|
|
|
29 edge_radius = 2; // [0:.1:10]
|
|
2
|
30 // paper size front to back, for the preview mockup and the lid sweep check
|
|
|
31 paper_depth = 90; // [10:1:300]
|
|
|
32 // paper height, for the preview mockup and the lid sweep check
|
|
|
33 paper_height = 90; // [10:1:300]
|
|
0
|
34
|
|
|
35 /* [walls] */
|
|
|
36 // wall thickness in extrusions
|
|
|
37 wall_lines = 4; // [2:1:10]
|
|
|
38 // lip thickness in extrusions: the inner part of the body wall, raised into the lid
|
|
|
39 lip_lines = 2; // [1:1:8]
|
|
|
40 // lip height in layers
|
|
|
41 lip_layers = 4; // [1:1:20]
|
|
|
42 // floor and lid top thickness in layers
|
|
|
43 floor_layers = 6; // [2:1:20]
|
|
1
|
44 // chamfer height in layers at the build plate edges of body and lid. each layer steps in by one layer height
|
|
|
45 chamfer_layers = 3; // [0:1:10]
|
|
0
|
46
|
|
|
47 /* [hinge] */
|
|
|
48 // diameter of the filament used as hinge pin
|
|
|
49 filament_diameter = 1.75; // [1:.05:3]
|
|
|
50 // number of hinge knuckles. the body gets the outer ones
|
|
|
51 hinge_knuckles = 5; // [3:2:15]
|
|
|
52 // knuckle wall around the pin hole, in extrusions
|
|
|
53 hinge_lines = 3; // [2:1:8]
|
|
|
54
|
|
|
55 /* [latch] */
|
|
|
56 // latch width
|
|
|
57 latch_width = 20; // [8:1:100]
|
|
|
58 // latch plate thickness in layers, printed flat
|
|
|
59 latch_layers = 8; // [4:1:20]
|
|
|
60 // radial overlap the hook tip has to pass at the filament bar. 0 for a free swinging latch
|
|
|
61 latch_detent = .3; // [0:.05:.7]
|
|
|
62 // grip tab length below the hook
|
|
|
63 latch_grip = 5; // [0:.5:20]
|
|
|
64
|
|
|
65 /* [print settings] */
|
|
|
66 line_width = .4; // [0:.01:1]
|
|
|
67 layer_height = .2; // [0:.01:.5]
|
|
|
68 clearance = .1; // [0:.01:.5]
|
|
|
69
|
|
|
70 module dummy() {}
|
|
|
71
|
|
|
72 epsilon = .001;
|
|
|
73 $fn = $preview ? 60 : 180;
|
|
|
74
|
|
|
75 lw = line_width;
|
|
|
76 lh = layer_height;
|
|
|
77 cl = clearance;
|
|
|
78
|
|
|
79 // walls
|
|
|
80 wall_t = wall_lines*lw;
|
|
|
81 // lid wall part that overlaps the lip from outside
|
|
|
82 skirt_t = (wall_lines - lip_lines)*lw;
|
|
|
83 lip_h = lip_layers*lh;
|
|
|
84 floor_t = floor_layers*lh;
|
|
1
|
85 chamfer_h = chamfer_layers*lh;
|
|
0
|
86 out_x = inner_depth + 2*wall_t;
|
|
|
87 out_y = inner_width + 2*wall_t;
|
|
|
88 edge_r = min(edge_radius, min(out_x, out_y)/2 - epsilon);
|
|
|
89
|
|
|
90 // knuckles, shared by hinge and latch
|
|
|
91 pin_d = filament_diameter + 2*cl;
|
|
|
92 knuckle_r = pin_d/2 + hinge_lines*lw;
|
|
|
93 // axis distance from the outer wall face
|
|
|
94 knuckle_u = knuckle_r + 2*cl;
|
|
|
95 // axial gap between knuckles
|
|
|
96 knuckle_gap = 2*cl;
|
|
|
97
|
|
2
|
98 // heights. the seam between body and lid sits on a layer boundary.
|
|
|
99 // the lid needs room for the wall around the latch pin hole, which sits
|
|
|
100 // one knuckle radius plus clearance above the seam, and for one layer of
|
|
|
101 // skirt wall above the recess over the lip. a body ratio that leaves less
|
|
|
102 // is lowered to the highest layer that fits
|
|
|
103 lid_min_h = max(2*knuckle_r + cl, floor_t + lip_h + 2*lh);
|
|
|
104 body_ih_max = floor((inner_height + floor_t - lid_min_h)/lh)*lh;
|
|
|
105 body_ih_req = round(body_ratio*inner_height/lh)*lh;
|
|
|
106 body_ih = min(body_ih_req, body_ih_max);
|
|
|
107 seam_z = floor_t + body_ih;
|
|
|
108 top_z = floor_t + inner_height + floor_t;
|
|
|
109 lid_h = top_z - seam_z;
|
|
|
110
|
|
0
|
111 // hinge
|
|
|
112 hinge_x = out_x/2 + knuckle_u;
|
|
|
113 hinge_span = out_y - 2*edge_r;
|
|
|
114 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles;
|
|
|
115
|
|
|
116 // latch. the flap hangs from lid knuckles and its hook wraps around a
|
|
|
117 // filament bar held by body knuckles straight below the flap axis.
|
|
|
118 // in the front frame u runs outward from the front face, z up
|
|
|
119 latch_x = -out_x/2 - knuckle_u;
|
|
|
120 latch_z = seam_z + knuckle_r + cl;
|
|
|
121 bar_z = seam_z - cl - knuckle_r;
|
|
|
122 bar_r = filament_diameter/2;
|
|
|
123 // distance between flap axis and bar axis
|
|
|
124 bar_h = latch_z - bar_z;
|
|
|
125 hook_ri = bar_r + cl;
|
|
|
126 hook_ro = hook_ri + hinge_lines*lw;
|
|
|
127 // outer radius of the bar minus radius of the hook tip, both around the
|
|
|
128 // flap axis, for a hook reaching angle b past the bottom of the bar
|
|
|
129 function _detent(b) =
|
|
|
130 bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]);
|
|
|
131 // bisection for the angle that gives latch_detent
|
|
|
132 function _hook_angle(lo, hi, n=40) =
|
|
|
133 n == 0 ? (lo + hi)/2 :
|
|
|
134 let(m = (lo + hi)/2)
|
|
|
135 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1);
|
|
|
136 hook_a = _hook_angle(0, 90);
|
|
|
137 plate_t = latch_layers*lh;
|
|
|
138 plate_u = knuckle_u + knuckle_r + 2*cl;
|
|
|
139 plate_bz = bar_z - hook_ro - latch_grip;
|
|
4
|
140 // a latch wider than the hinge span is narrowed to it
|
|
|
141 latch_w = min(latch_width, hinge_span);
|
|
|
142 latch_slot = (latch_w - 2*knuckle_gap)/3;
|
|
0
|
143 // y start of the two outer latch slots
|
|
4
|
144 latch_outer_y0 = [-latch_w/2, latch_slot/2 + knuckle_gap];
|
|
0
|
145
|
|
|
146 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar");
|
|
|
147 assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles");
|
|
2
|
148 assert(body_ih > 0, "inner height too low for the lid");
|
|
1
|
149 assert(chamfer_h <= floor_t, "chamfer higher than the floor");
|
|
0
|
150
|
|
|
151 // lid sweep over a centred paper stack: radius of the lowest lid ceiling
|
|
|
152 // point over the paper minus radius of the paper's front top corner
|
|
|
153 sweep_margin =
|
|
|
154 norm([hinge_x + inner_depth/2, lip_h + lh])
|
|
2
|
155 - norm([hinge_x + paper_depth/2, floor_t + paper_height - seam_z]);
|
|
0
|
156
|
|
|
157 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions");
|
|
|
158 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm");
|
|
|
159 echo("outer size", out_x, out_y, top_z, "mm");
|
|
1
|
160 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers");
|
|
2
|
161 if (body_ih < body_ih_req)
|
|
|
162 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ",
|
|
|
163 body_ih/inner_height));
|
|
|
164 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height);
|
|
0
|
165 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm");
|
|
|
166 echo("hinge knuckle length", knuckle_l, "mm");
|
|
4
|
167 if (latch_w < latch_width)
|
|
|
168 echo(str("WARNING: latch_width ", latch_width, " is wider than the box front, using ",
|
|
|
169 latch_w));
|
|
|
170 echo("latch width", latch_w, "mm");
|
|
0
|
171 echo("latch plate outer face", plate_u + plate_t, "mm from the front");
|
|
|
172 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm");
|
|
|
173 echo("lid sweep clearance over centred paper", sweep_margin, "mm");
|
|
|
174
|
|
|
175 // rounded box outline, inset by d
|
|
|
176 module _outline(d) {
|
|
|
177 r = max(edge_r - d, 0);
|
|
|
178 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true);
|
|
|
179 }
|
|
|
180
|
|
1
|
181 // outer box shape of height h, the bottom edge chamfered in steps of one
|
|
|
182 // layer, each step inset by one layer height
|
|
|
183 module _block(h) {
|
|
|
184 for (i = [0:1:chamfer_layers - 1])
|
|
|
185 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh);
|
|
|
186 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0);
|
|
|
187 }
|
|
|
188
|
|
0
|
189 // extrude a 2d profile drawn in x/z between y0 and y1
|
|
|
190 module _yslab(y0, y1) {
|
|
|
191 translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0) children();
|
|
|
192 }
|
|
|
193
|
|
|
194 // frame with u outward from the back face
|
|
|
195 module _back() {
|
|
|
196 translate([out_x/2, 0, 0]) children();
|
|
|
197 }
|
|
|
198
|
|
|
199 // frame with u outward from the front face
|
|
|
200 module _front() {
|
|
|
201 translate([-out_x/2, 0, 0]) mirror([1, 0, 0]) children();
|
|
|
202 }
|
|
|
203
|
|
|
204 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap);
|
|
|
205
|
|
|
206 module _hinge_pin() {
|
|
|
207 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0])
|
|
|
208 cylinder(d=pin_d, h=out_y + 2, center=true);
|
|
|
209 }
|
|
|
210
|
|
|
211 module _latch_pin() {
|
|
|
212 translate([latch_x, 0, latch_z]) rotate([90, 0, 0])
|
|
4
|
213 cylinder(d=pin_d, h=latch_w + 2, center=true);
|
|
0
|
214 }
|
|
|
215
|
|
|
216 module _bar_pin() {
|
|
|
217 translate([latch_x, 0, bar_z]) rotate([90, 0, 0])
|
|
4
|
218 cylinder(d=pin_d, h=latch_w + 2, center=true);
|
|
0
|
219 }
|
|
|
220
|
|
|
221 module body() {
|
|
|
222 // knuckle at height z with a web down to the wall up to z1, chamfered
|
|
|
223 // below for printing
|
|
|
224 module _knuckle(z, z1) {
|
|
|
225 hull() {
|
|
|
226 translate([knuckle_u, z]) circle(r=knuckle_r);
|
|
|
227 translate([-epsilon, z - knuckle_r - knuckle_u])
|
|
|
228 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]);
|
|
|
229 }
|
|
|
230 }
|
|
|
231
|
|
|
232 difference() {
|
|
|
233 union() {
|
|
1
|
234 _block(seam_z);
|
|
0
|
235 translate([0, 0, seam_z - epsilon])
|
|
|
236 linear_extrude(lip_h + epsilon)
|
|
|
237 difference() {
|
|
|
238 _outline(skirt_t + cl);
|
|
|
239 _outline(wall_t);
|
|
|
240 }
|
|
|
241 for (i = [0:2:hinge_knuckles - 1])
|
|
|
242 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l)
|
|
|
243 _knuckle(seam_z, seam_z - cl);
|
|
|
244 for (y0 = latch_outer_y0)
|
|
|
245 _front() _yslab(y0, y0 + latch_slot) _knuckle(bar_z, bar_z + knuckle_r);
|
|
|
246 }
|
|
|
247 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t);
|
|
|
248 _hinge_pin();
|
|
|
249 _bar_pin();
|
|
|
250 }
|
|
|
251 }
|
|
|
252
|
|
|
253 // in assembly position, closed
|
|
|
254 module lid() {
|
|
|
255 // knuckle at height z with a web up to the wall from z0, chamfered
|
|
2
|
256 // towards the lid top for printing upside down. the web reaches into
|
|
|
257 // the wall by the chamfer height, so where it meets the lid top it
|
|
|
258 // fills the edge chamfer. a knuckle that would reach past the lid top
|
|
|
259 // is cut off there and stands on the print bed
|
|
0
|
260 module _knuckle(z, z0) {
|
|
2
|
261 web_u = chamfer_h + epsilon;
|
|
|
262 intersection() {
|
|
|
263 hull() {
|
|
|
264 translate([knuckle_u, z]) circle(r=knuckle_r);
|
|
|
265 translate([-web_u, z0])
|
|
|
266 square([web_u, z + knuckle_r + knuckle_u - z0]);
|
|
|
267 }
|
|
|
268 translate([-web_u - 1, z - knuckle_r - 1])
|
|
|
269 square([web_u + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]);
|
|
0
|
270 }
|
|
|
271 }
|
|
|
272
|
|
|
273 difference() {
|
|
|
274 union() {
|
|
1
|
275 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h);
|
|
0
|
276 for (i = [1:2:hinge_knuckles - 1])
|
|
|
277 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l)
|
|
|
278 _knuckle(seam_z, seam_z + cl);
|
|
|
279 for (y0 = latch_outer_y0)
|
|
|
280 _front() _yslab(y0, y0 + latch_slot) _knuckle(latch_z, seam_z + cl);
|
|
|
281 }
|
|
|
282 translate([0, 0, seam_z - epsilon])
|
|
|
283 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t);
|
|
|
284 // recess over the lip, one layer higher than the lip
|
|
|
285 translate([0, 0, seam_z - epsilon])
|
|
|
286 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t);
|
|
|
287 _hinge_pin();
|
|
|
288 _latch_pin();
|
|
|
289 }
|
|
|
290 }
|
|
|
291
|
|
|
292 // in assembly position, closed
|
|
|
293 module latch() {
|
|
|
294 // hook around the bar, from the plate side down under the bar and
|
|
4
|
295 // hook_a degrees up its wall side. its back is filled with a web down
|
|
|
296 // to the plate, sloped like the knuckle webs. a web reaching closer
|
|
|
297 // than 2 extrusions to the grip edge is cut off there, but never above
|
|
|
298 // the bottom of the hook
|
|
0
|
299 module _hook() {
|
|
|
300 tip_a = 270 - hook_a;
|
|
4
|
301 web_z = bar_z - hook_ro - (plate_u - knuckle_u);
|
|
|
302 cut_z = min(plate_bz + 2*lw, bar_z - hook_ro);
|
|
0
|
303 difference() {
|
|
4
|
304 intersection() {
|
|
|
305 hull() {
|
|
|
306 translate([knuckle_u, bar_z]) circle(r=hook_ro);
|
|
|
307 translate([plate_u, web_z]) square([epsilon, bar_z - web_z]);
|
|
|
308 }
|
|
|
309 translate([0, cut_z]) square([plate_u + epsilon, bar_z - cut_z]);
|
|
0
|
310 }
|
|
|
311 translate([knuckle_u, bar_z]) circle(r=hook_ri);
|
|
|
312 // open wedge over the top and the wall side of the bar
|
|
|
313 translate([knuckle_u, bar_z])
|
|
|
314 polygon(concat([[0, 0]],
|
|
|
315 [for (a = [0:10:tip_a]) 2*hook_ro*[cos(a), sin(a)]],
|
|
|
316 [2*hook_ro*[cos(tip_a), sin(tip_a)]]));
|
|
|
317 }
|
|
|
318 }
|
|
|
319
|
|
|
320 difference() {
|
|
|
321 _front() union() {
|
|
4
|
322 _yslab(-latch_w/2, latch_w/2)
|
|
0
|
323 translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]);
|
|
|
324 _yslab(-latch_slot/2, latch_slot/2) {
|
|
|
325 hull() {
|
|
|
326 translate([knuckle_u, latch_z]) circle(r=knuckle_r);
|
|
|
327 translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]);
|
|
|
328 }
|
|
|
329 _hook();
|
|
|
330 }
|
|
|
331 }
|
|
|
332 _latch_pin();
|
|
|
333 }
|
|
|
334 }
|
|
|
335
|
|
|
336 module _paper() {
|
|
|
337 stack_t = inner_width - 2;
|
|
|
338 color("white", .6)
|
|
2
|
339 translate([-paper_depth/2, -stack_t/2, floor_t])
|
|
|
340 cube([paper_depth, stack_t, paper_height]);
|
|
0
|
341 }
|
|
|
342
|
|
|
343 // filament of length l along y at x, z
|
|
|
344 module _filament(x, z, l) {
|
|
|
345 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0])
|
|
|
346 cylinder(d=filament_diameter, h=l, center=true);
|
|
|
347 }
|
|
|
348
|
|
|
349 module _assembly() {
|
|
|
350 color("steelblue") body();
|
|
|
351 if (preview_hardware && $preview) {
|
|
|
352 _filament(hinge_x, seam_z, hinge_span);
|
|
4
|
353 _filament(latch_x, bar_z, latch_w);
|
|
0
|
354 }
|
|
|
355 translate([hinge_x, 0, seam_z]) rotate([0, preview_lid_angle, 0])
|
|
|
356 translate([-hinge_x, 0, -seam_z]) {
|
|
|
357 color("lightsteelblue") lid();
|
|
4
|
358 if (preview_hardware && $preview) _filament(latch_x, latch_z, latch_w);
|
|
0
|
359 translate([latch_x, 0, latch_z]) rotate([0, preview_latch_angle, 0])
|
|
|
360 translate([-latch_x, 0, -latch_z]) color("orange") latch();
|
|
|
361 }
|
|
|
362 if (preview_paper && $preview) _paper();
|
|
|
363 }
|
|
|
364
|
|
|
365 module part_view() {
|
|
|
366 cut_s = max(out_x/2 + plate_u + plate_t, top_z)
|
|
|
367 + (preview_lid_angle > 0 ? out_x : 0) + 1;
|
|
|
368 if ($preview && preview_cut)
|
|
|
369 difference() {
|
|
|
370 children();
|
|
|
371 translate([-cut_s, -cut_s, -cut_s]) cube([2*cut_s, cut_s, 2*cut_s]);
|
|
|
372 }
|
|
|
373 else
|
|
|
374 children();
|
|
|
375 }
|
|
|
376
|
|
|
377 module main() {
|
|
|
378 if (part == "all")
|
|
|
379 part_view() _assembly();
|
|
|
380 else if (part == "body")
|
|
|
381 part_view() body();
|
|
|
382 else if (part == "lid")
|
|
|
383 part_view()
|
|
|
384 if ($preview) lid();
|
|
|
385 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid();
|
|
|
386 else if (part == "latch")
|
|
|
387 part_view()
|
|
|
388 if ($preview) latch();
|
|
|
389 else translate([latch_z, 0, out_x/2 + plate_u + plate_t])
|
|
|
390 rotate([0, -90, 0]) latch();
|
|
|
391 }
|
|
|
392
|
|
|
393 main();
|
|
|
394
|
|
|
395 function paramstring(prefix="", suffix="") = str(
|
|
|
396 prefix,
|
|
|
397 part == "all" ? "" : str(part, "_"),
|
|
|
398 "w", inner_width, "d", inner_depth, "h", inner_height,
|
|
2
|
399 "b", round(100*body_ih/inner_height),
|
|
0
|
400 "_lw", round(100*line_width), "lh", round(100*layer_height),
|
|
|
401 suffix);
|
|
|
402
|
|
|
403 echo(paramstring("hinged_box_"));
|