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