wobblyhead hg > 3dprints > hinged_box
diff main.scad @ 8:ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
Add latch_style with a new block latch: a solid piece in the middle slot
with the profile of the body knuckles, extended below the hook by
latch_grip. Between knuckle and hook only the knuckle ring and the front
wall remain; below the bar the opening follows the hook tip line to the
back face. A notch at the bottom of the back face takes a fingernail.
Add latch_middle_ratio for the share of the latch width taken by the
middle knuckle, clamped with a warning so no slot is narrower than two
extrusions.
Add latch_plate_full. Without it the plate is only as wide as the middle
slot, and the latch exports standing on its side with the plate
thickness rounded up to whole extrusions. The block also prints on its
side.
The latch file name gets the style, and all names get the middle share
when it is not .33. Extrude slabs with convexity 4 so the preview shows
the block profile correctly. README updated.
| author | ark |
|---|---|
| date | 2026-11-17 12:32 +0100 |
| parents | 1933892bab51 |
| children | 4b89f95689a8 |
line wrap: on
line diff
--- a/main.scad Tue Nov 17 08:50:46 2026 +0100 +++ b/main.scad Tue Nov 17 12:32:19 2026 +0100 @@ -65,13 +65,19 @@ hinge_lines = 3; // [2:1:8] /* [latch] */ +// latch shape: a plate in front of the knuckles joining knuckle and hook, or a solid block between the bar knuckles +latch_style = "plate"; // [plate, block] // latch width latch_width = 20; // [8:1:100] -// latch plate thickness in layers, printed flat +// share of the latch width taken by the middle knuckle that carries the latch. the outer knuckles share the rest +latch_middle_ratio = .33; // [.1:.01:.9] +// plate style: plate across the full latch width, printed flat. otherwise only as wide as the middle knuckle, printed standing on its side +latch_plate_full = true; +// latch plate thickness in layers. a plate printed on its side is rounded up to whole extrusions latch_layers = 8; // [4:1:20] // radial overlap the hook tip has to pass at the filament bar. 0 for a free swinging latch latch_detent = .3; // [0:.05:.7] -// grip tab length below the hook +// grip length below the hook: the plate's grip tab, or the block's extension latch_grip = 5; // [0:.5:20] // hook wall around the filament bar, in extrusions latch_hook_lines = 3; // [2:1:8] @@ -131,8 +137,8 @@ hinge_span = out_y - 2*edge_r; knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; -// latch. the flap hangs from lid knuckles and its hook wraps around a -// filament bar held by body knuckles straight below the flap axis. +// latch. the latch hangs from lid knuckles and its hook wraps around a +// filament bar held by body knuckles straight below the latch axis. // in the front frame u runs outward from the front face, z up. // a latch wider than the hinge span is narrowed to it latch_w = min(latch_width, hinge_span); @@ -145,7 +151,7 @@ hook_ri = bar_r + cl; hook_ro = hook_ri + latch_hook_lines*lw; // outer radius of the bar minus radius of the hook tip, both around the -// flap axis, for a hook reaching angle b past the bottom of the bar +// latch axis, for a hook reaching angle b past the bottom of the bar function _detent(b) = bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]); // bisection for the angle that gives latch_detent @@ -154,12 +160,46 @@ let(m = (lo + hi)/2) _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); hook_a = _hook_angle(0, 90); -plate_t = latch_layers*lh; + +// knuckle slots across the latch width: the middle one carries the latch, +// the outer ones have a lid knuckle above and a body knuckle below. a +// ratio that leaves a slot narrower than 2 extrusions is clamped +latch_span = latch_w - 2*knuckle_gap; +slot_min = 2*lw; +latch_ratio = min(max(latch_middle_ratio, slot_min/latch_span), 1 - 2*slot_min/latch_span); +latch_mid = latch_ratio*latch_span; +latch_outer = (latch_span - latch_mid)/2; +// y start of the two outer latch slots +latch_outer_y0 = [-latch_w/2, latch_mid/2 + knuckle_gap]; + +// the latch prints standing on its side, its profile in the print plane, +// unless it is a plate across the full latch width +latch_block = latch_style == "block"; +latch_on_side = latch_block || !latch_plate_full; + +// plate style. on its side, the thickness is rounded up to whole +// extrusions; the small margin keeps an exact multiple from rounding up +plate_w = latch_on_side ? latch_mid : latch_w; +plate_lines = ceil(latch_layers*lh/lw - .001); +plate_t = latch_on_side ? plate_lines*lw : latch_layers*lh; plate_u = knuckle_u + knuckle_r + 2*cl; plate_bz = bar_z - hook_ro - latch_grip; -latch_slot = (latch_w - 2*knuckle_gap)/3; -// y start of the two outer latch slots -latch_outer_y0 = [-latch_w/2, latch_slot/2 + knuckle_gap]; + +// block style: the profile of the body knuckles, reaching from the latch +// knuckle down past the hook by latch_grip. blk_r is the radius of the +// rounded front, blk_back the gap between back face and wall, blk_cz the +// centre of the lowest round and blk_bz the bottom end of the back face +blk_r = max(knuckle_r, hook_ro); +blk_back = 2*cl; +blk_cz = bar_z - latch_grip; +blk_bz = blk_cz - blk_r - (knuckle_u - blk_back); +// fingernail notch in the back face at the bottom edge: 3 extrusions +// deep, 8 extrusions high, kept 2 extrusions below the hook +nail_d = 3*lw; +nail_h = min(8*lw, bar_z - hook_ro - 2*lw - blk_bz); + +// how far the latch reaches out from the front face +latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); assert(knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); @@ -196,9 +236,24 @@ if (latch_w < latch_width) echo(str("WARNING: latch_width ", latch_width, " is wider than the hinge span, using ", latch_w)); +if (latch_ratio != latch_middle_ratio) + echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, + " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); echo("hinge knuckle length", knuckle_l, "mm"); -echo("latch plate outer face", plate_u + plate_t, "mm from the front"); +echo("latch knuckle length: middle", latch_mid, "mm, outer", latch_outer, "mm"); +echo(str("latch style ", latch_style, ", printed ", latch_on_side ? "on its side" : "flat")); +if (latch_block) { + echo("latch block length below the hook", latch_grip, "mm"); + if (nail_h > 0) + echo("fingernail notch", nail_d, "mm deep, reaching", nail_h, "mm above the bottom edge"); + else + echo("WARNING: latch_grip too short for the fingernail notch"); +} else if (latch_on_side) + echo("latch plate thickness", plate_t, "mm", plate_lines, "extrusions, width", plate_w, "mm"); +else + echo("latch plate thickness", plate_t, "mm", latch_layers, "layers, width", plate_w, "mm"); +echo("latch outer face", latch_front_u, "mm from the front"); echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); if (cont_x < content_depth) echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); @@ -225,7 +280,7 @@ // extrude a 2d profile drawn in x/z between y0 and y1 module _yslab(y0, y1) { - translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0) children(); + translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0, convexity=4) children(); } // frame with u outward from the back face @@ -289,7 +344,7 @@ _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) _knuckle(seam_z, seam_z - cl); for (y0 = latch_outer_y0) - _front() _yslab(y0, y0 + latch_slot) _knuckle(bar_z, bar_z + knuckle_r); + _front() _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); } translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); _hinge_pin(); @@ -334,7 +389,7 @@ _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) _knuckle(seam_z, seam_z + cl); for (y0 = latch_outer_y0) - _front() _yslab(y0, y0 + latch_slot) _knuckle(latch_z, seam_z + cl); + _front() _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); } translate([0, 0, seam_z - epsilon]) linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); @@ -346,39 +401,92 @@ } } -// in assembly position, closed +// in assembly position, closed. the plate style has a knuckle and a hook +// in the middle slot, joined by a plate in front of the outer knuckles. the +// block style is one solid profile across the middle slot module latch() { + tip_a = 270 - hook_a; + axis = [knuckle_u, latch_z]; + bar = [knuckle_u, bar_z]; + // length of the hook tip line from the bar centre to past the back face + tip_l = (knuckle_u + 1)/max(abs(cos(tip_a)), .1); + + // sector of radius r from angle a0 to a1, counterclockwise + module _sector(r, a0, a1) { + polygon(concat([[0, 0]], + [for (a = [a0:10:a1]) r*[cos(a), sin(a)]], + [r*[cos(a1), sin(a1)]])); + } + // hook around the bar, from the plate side down under the bar and // hook_a degrees up its wall side module _hook() { - tip_a = 270 - hook_a; difference() { hull() { translate([knuckle_u, bar_z]) circle(r=hook_ro); translate([knuckle_u, bar_z - hook_ro]) square([plate_u - knuckle_u + epsilon, hook_ro]); } - translate([knuckle_u, bar_z]) circle(r=hook_ri); + translate(bar) circle(r=hook_ri); // open wedge over the top and the wall side of the bar - translate([knuckle_u, bar_z]) - polygon(concat([[0, 0]], - [for (a = [0:10:tip_a]) 2*hook_ro*[cos(a), sin(a)]], - [2*hook_ro*[cos(tip_a), sin(tip_a)]])); + translate(bar) _sector(2*hook_ro, 0, tip_a); + } + } + + module _plate() { + _yslab(-plate_w/2, plate_w/2) + translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]); + _yslab(-latch_mid/2, latch_mid/2) { + hull() { + translate(axis) circle(r=knuckle_r); + translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]); + } + _hook(); + } + } + + // profile of the block: rounded at the front, the back face flat along + // the wall, sloped at the bottom like the body knuckles + module _block() { + difference() { + intersection() { + hull() { + translate(axis) circle(r=knuckle_r); + translate(bar) circle(r=blk_r); + translate([knuckle_u, blk_cz]) circle(r=blk_r); + translate([blk_back, blk_bz]) square([epsilon, latch_z - blk_bz]); + } + // keep the back face off the wall where the hook is larger + // than the knuckle + translate([blk_back, blk_bz - 1]) + square([knuckle_u + blk_r + 1, latch_z + knuckle_r - blk_bz + 2]); + } + translate(bar) circle(r=hook_ri); + // opening for the bar, leaving the knuckle ring and the front + // wall: from the knuckle down to the bar, front to the far side + // of the bar hole, and on the wall side down to the line of the + // hook tip face, which runs on through the bar centre to the + // back face + difference() { + polygon([ + bar, + bar + tip_l*[cos(tip_a), sin(tip_a)], + [-1, latch_z], + [knuckle_u + hook_ri, latch_z], + [knuckle_u + hook_ri, bar_z]]); + translate(axis) circle(r=knuckle_r); + } + // fingernail notch + if (nail_h > 0) + translate([blk_back - epsilon, blk_bz - epsilon]) + square([nail_d + epsilon, nail_h + epsilon]); } } difference() { - _front() union() { - _yslab(-latch_w/2, latch_w/2) - translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]); - _yslab(-latch_slot/2, latch_slot/2) { - hull() { - translate([knuckle_u, latch_z]) circle(r=knuckle_r); - translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]); - } - _hook(); - } - } + _front() + if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); + else _plate(); _latch_pin(); } } @@ -414,7 +522,7 @@ } module part_view() { - cut_s = max(out_x/2 + plate_u + plate_t, top_z) + cut_s = max(out_x/2 + latch_front_u, top_z) + (preview_lid_angle > 0 ? out_x : 0) + 1; if ($preview && preview_cut) difference() { @@ -437,7 +545,12 @@ else if (part == "latch") part_view() if ($preview) latch(); - else translate([latch_z, 0, out_x/2 + plate_u + plate_t]) + // on its side: the width along z, standing on the print bed + else if (latch_on_side) + translate([0, 0, latch_mid/2]) rotate([90, 0, 0]) + translate([-latch_x, 0, -latch_z]) latch(); + // flat: the plate face on the print bed + else translate([latch_z, 0, out_x/2 + latch_front_u]) rotate([0, -90, 0]) latch(); } @@ -446,9 +559,13 @@ function paramstring(prefix="", suffix="") = str( prefix, part == "all" ? "" : str(part, "_"), + part == "latch" ? + str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", "w", inner_width, "d", inner_depth, "h", inner_height, "b", round(100*body_ih/inner_height), + // latch middle share, only when it differs from the default + round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)), "_lw", round(100*line_width), "lh", round(100*layer_height), suffix);
