|
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;
|
|
|
140 latch_slot = (latch_width - 2*knuckle_gap)/3;
|
|
|
141 // y start of the two outer latch slots
|
|
|
142 latch_outer_y0 = [-latch_width/2, latch_slot/2 + knuckle_gap];
|
|
|
143
|
|
|
144 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar");
|
|
|
145 assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles");
|
|
|
146 assert(latch_width <= hinge_span, "latch wider than the box front");
|
|
2
|
147 assert(body_ih > 0, "inner height too low for the lid");
|
|
1
|
148 assert(chamfer_h <= floor_t, "chamfer higher than the floor");
|
|
0
|
149
|
|
|
150 // lid sweep over a centred paper stack: radius of the lowest lid ceiling
|
|
|
151 // point over the paper minus radius of the paper's front top corner
|
|
|
152 sweep_margin =
|
|
|
153 norm([hinge_x + inner_depth/2, lip_h + lh])
|
|
2
|
154 - norm([hinge_x + paper_depth/2, floor_t + paper_height - seam_z]);
|
|
0
|
155
|
|
|
156 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions");
|
|
|
157 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm");
|
|
|
158 echo("outer size", out_x, out_y, top_z, "mm");
|
|
1
|
159 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers");
|
|
2
|
160 if (body_ih < body_ih_req)
|
|
|
161 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ",
|
|
|
162 body_ih/inner_height));
|
|
|
163 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height);
|
|
0
|
164 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm");
|
|
|
165 echo("hinge knuckle length", knuckle_l, "mm");
|
|
|
166 echo("latch plate outer face", plate_u + plate_t, "mm from the front");
|
|
|
167 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm");
|
|
|
168 echo("lid sweep clearance over centred paper", sweep_margin, "mm");
|
|
|
169
|
|
|
170 // rounded box outline, inset by d
|
|
|
171 module _outline(d) {
|
|
|
172 r = max(edge_r - d, 0);
|
|
|
173 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true);
|
|
|
174 }
|
|
|
175
|
|
1
|
176 // outer box shape of height h, the bottom edge chamfered in steps of one
|
|
|
177 // layer, each step inset by one layer height
|
|
|
178 module _block(h) {
|
|
|
179 for (i = [0:1:chamfer_layers - 1])
|
|
|
180 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh);
|
|
|
181 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0);
|
|
|
182 }
|
|
|
183
|
|
0
|
184 // extrude a 2d profile drawn in x/z between y0 and y1
|
|
|
185 module _yslab(y0, y1) {
|
|
|
186 translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0) children();
|
|
|
187 }
|
|
|
188
|
|
|
189 // frame with u outward from the back face
|
|
|
190 module _back() {
|
|
|
191 translate([out_x/2, 0, 0]) children();
|
|
|
192 }
|
|
|
193
|
|
|
194 // frame with u outward from the front face
|
|
|
195 module _front() {
|
|
|
196 translate([-out_x/2, 0, 0]) mirror([1, 0, 0]) children();
|
|
|
197 }
|
|
|
198
|
|
|
199 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap);
|
|
|
200
|
|
|
201 module _hinge_pin() {
|
|
|
202 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0])
|
|
|
203 cylinder(d=pin_d, h=out_y + 2, center=true);
|
|
|
204 }
|
|
|
205
|
|
|
206 module _latch_pin() {
|
|
|
207 translate([latch_x, 0, latch_z]) rotate([90, 0, 0])
|
|
|
208 cylinder(d=pin_d, h=latch_width + 2, center=true);
|
|
|
209 }
|
|
|
210
|
|
|
211 module _bar_pin() {
|
|
|
212 translate([latch_x, 0, bar_z]) rotate([90, 0, 0])
|
|
|
213 cylinder(d=pin_d, h=latch_width + 2, center=true);
|
|
|
214 }
|
|
|
215
|
|
|
216 module body() {
|
|
|
217 // knuckle at height z with a web down to the wall up to z1, chamfered
|
|
|
218 // below for printing
|
|
|
219 module _knuckle(z, z1) {
|
|
|
220 hull() {
|
|
|
221 translate([knuckle_u, z]) circle(r=knuckle_r);
|
|
|
222 translate([-epsilon, z - knuckle_r - knuckle_u])
|
|
|
223 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]);
|
|
|
224 }
|
|
|
225 }
|
|
|
226
|
|
|
227 difference() {
|
|
|
228 union() {
|
|
1
|
229 _block(seam_z);
|
|
0
|
230 translate([0, 0, seam_z - epsilon])
|
|
|
231 linear_extrude(lip_h + epsilon)
|
|
|
232 difference() {
|
|
|
233 _outline(skirt_t + cl);
|
|
|
234 _outline(wall_t);
|
|
|
235 }
|
|
|
236 for (i = [0:2:hinge_knuckles - 1])
|
|
|
237 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l)
|
|
|
238 _knuckle(seam_z, seam_z - cl);
|
|
|
239 for (y0 = latch_outer_y0)
|
|
|
240 _front() _yslab(y0, y0 + latch_slot) _knuckle(bar_z, bar_z + knuckle_r);
|
|
|
241 }
|
|
|
242 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t);
|
|
|
243 _hinge_pin();
|
|
|
244 _bar_pin();
|
|
|
245 }
|
|
|
246 }
|
|
|
247
|
|
|
248 // in assembly position, closed
|
|
|
249 module lid() {
|
|
|
250 // knuckle at height z with a web up to the wall from z0, chamfered
|
|
2
|
251 // towards the lid top for printing upside down. the web reaches into
|
|
|
252 // the wall by the chamfer height, so where it meets the lid top it
|
|
|
253 // fills the edge chamfer. a knuckle that would reach past the lid top
|
|
|
254 // is cut off there and stands on the print bed
|
|
0
|
255 module _knuckle(z, z0) {
|
|
2
|
256 web_u = chamfer_h + epsilon;
|
|
|
257 intersection() {
|
|
|
258 hull() {
|
|
|
259 translate([knuckle_u, z]) circle(r=knuckle_r);
|
|
|
260 translate([-web_u, z0])
|
|
|
261 square([web_u, z + knuckle_r + knuckle_u - z0]);
|
|
|
262 }
|
|
|
263 translate([-web_u - 1, z - knuckle_r - 1])
|
|
|
264 square([web_u + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]);
|
|
0
|
265 }
|
|
|
266 }
|
|
|
267
|
|
|
268 difference() {
|
|
|
269 union() {
|
|
1
|
270 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h);
|
|
0
|
271 for (i = [1:2:hinge_knuckles - 1])
|
|
|
272 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l)
|
|
|
273 _knuckle(seam_z, seam_z + cl);
|
|
|
274 for (y0 = latch_outer_y0)
|
|
|
275 _front() _yslab(y0, y0 + latch_slot) _knuckle(latch_z, seam_z + cl);
|
|
|
276 }
|
|
|
277 translate([0, 0, seam_z - epsilon])
|
|
|
278 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t);
|
|
|
279 // recess over the lip, one layer higher than the lip
|
|
|
280 translate([0, 0, seam_z - epsilon])
|
|
|
281 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t);
|
|
|
282 _hinge_pin();
|
|
|
283 _latch_pin();
|
|
|
284 }
|
|
|
285 }
|
|
|
286
|
|
|
287 // in assembly position, closed
|
|
|
288 module latch() {
|
|
|
289 // hook around the bar, from the plate side down under the bar and
|
|
|
290 // hook_a degrees up its wall side
|
|
|
291 module _hook() {
|
|
|
292 tip_a = 270 - hook_a;
|
|
|
293 difference() {
|
|
|
294 hull() {
|
|
|
295 translate([knuckle_u, bar_z]) circle(r=hook_ro);
|
|
|
296 translate([knuckle_u, bar_z - hook_ro])
|
|
|
297 square([plate_u - knuckle_u + epsilon, hook_ro]);
|
|
|
298 }
|
|
|
299 translate([knuckle_u, bar_z]) circle(r=hook_ri);
|
|
|
300 // open wedge over the top and the wall side of the bar
|
|
|
301 translate([knuckle_u, bar_z])
|
|
|
302 polygon(concat([[0, 0]],
|
|
|
303 [for (a = [0:10:tip_a]) 2*hook_ro*[cos(a), sin(a)]],
|
|
|
304 [2*hook_ro*[cos(tip_a), sin(tip_a)]]));
|
|
|
305 }
|
|
|
306 }
|
|
|
307
|
|
|
308 difference() {
|
|
|
309 _front() union() {
|
|
|
310 _yslab(-latch_width/2, latch_width/2)
|
|
|
311 translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]);
|
|
|
312 _yslab(-latch_slot/2, latch_slot/2) {
|
|
|
313 hull() {
|
|
|
314 translate([knuckle_u, latch_z]) circle(r=knuckle_r);
|
|
|
315 translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]);
|
|
|
316 }
|
|
|
317 _hook();
|
|
|
318 }
|
|
|
319 }
|
|
|
320 _latch_pin();
|
|
|
321 }
|
|
|
322 }
|
|
|
323
|
|
|
324 module _paper() {
|
|
|
325 stack_t = inner_width - 2;
|
|
|
326 color("white", .6)
|
|
2
|
327 translate([-paper_depth/2, -stack_t/2, floor_t])
|
|
|
328 cube([paper_depth, stack_t, paper_height]);
|
|
0
|
329 }
|
|
|
330
|
|
|
331 // filament of length l along y at x, z
|
|
|
332 module _filament(x, z, l) {
|
|
|
333 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0])
|
|
|
334 cylinder(d=filament_diameter, h=l, center=true);
|
|
|
335 }
|
|
|
336
|
|
|
337 module _assembly() {
|
|
|
338 color("steelblue") body();
|
|
|
339 if (preview_hardware && $preview) {
|
|
|
340 _filament(hinge_x, seam_z, hinge_span);
|
|
|
341 _filament(latch_x, bar_z, latch_width);
|
|
|
342 }
|
|
|
343 translate([hinge_x, 0, seam_z]) rotate([0, preview_lid_angle, 0])
|
|
|
344 translate([-hinge_x, 0, -seam_z]) {
|
|
|
345 color("lightsteelblue") lid();
|
|
|
346 if (preview_hardware && $preview) _filament(latch_x, latch_z, latch_width);
|
|
|
347 translate([latch_x, 0, latch_z]) rotate([0, preview_latch_angle, 0])
|
|
|
348 translate([-latch_x, 0, -latch_z]) color("orange") latch();
|
|
|
349 }
|
|
|
350 if (preview_paper && $preview) _paper();
|
|
|
351 }
|
|
|
352
|
|
|
353 module part_view() {
|
|
|
354 cut_s = max(out_x/2 + plate_u + plate_t, top_z)
|
|
|
355 + (preview_lid_angle > 0 ? out_x : 0) + 1;
|
|
|
356 if ($preview && preview_cut)
|
|
|
357 difference() {
|
|
|
358 children();
|
|
|
359 translate([-cut_s, -cut_s, -cut_s]) cube([2*cut_s, cut_s, 2*cut_s]);
|
|
|
360 }
|
|
|
361 else
|
|
|
362 children();
|
|
|
363 }
|
|
|
364
|
|
|
365 module main() {
|
|
|
366 if (part == "all")
|
|
|
367 part_view() _assembly();
|
|
|
368 else if (part == "body")
|
|
|
369 part_view() body();
|
|
|
370 else if (part == "lid")
|
|
|
371 part_view()
|
|
|
372 if ($preview) lid();
|
|
|
373 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid();
|
|
|
374 else if (part == "latch")
|
|
|
375 part_view()
|
|
|
376 if ($preview) latch();
|
|
|
377 else translate([latch_z, 0, out_x/2 + plate_u + plate_t])
|
|
|
378 rotate([0, -90, 0]) latch();
|
|
|
379 }
|
|
|
380
|
|
|
381 main();
|
|
|
382
|
|
|
383 function paramstring(prefix="", suffix="") = str(
|
|
|
384 prefix,
|
|
|
385 part == "all" ? "" : str(part, "_"),
|
|
|
386 "w", inner_width, "d", inner_depth, "h", inner_height,
|
|
2
|
387 "b", round(100*body_ih/inner_height),
|
|
0
|
388 "_lw", round(100*line_width), "lh", round(100*layer_height),
|
|
|
389 suffix);
|
|
|
390
|
|
|
391 echo(paramstring("hinged_box_"));
|