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