wobblyhead hg > 3dprints > hinged_box
annotate main.scad @ 10:a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
Add back_side to put the hinge or a latch on the back, and latch_front,
latch_left and latch_right checkboxes. The latch hardware is modelled in
a face frame and placed on each latched side. All latches share one
width, clamped to the narrowest latched face; the console lists the
latched sides and the number of latches to print. A layout other than
front latch with back hinge adds an l token with the side letters to
the file name.
Replace preview_lid_angle with preview_lid_open in percent: with the
hinge 100 turns the lid by 180 degrees, without it lifts the lid by one
body height. Presets converted. README updated.
| author | ark |
|---|---|
| date | 2026-11-17 12:53 +0100 |
| parents | 4b89f95689a8 |
| children | 7bef1d0cb914 |
| rev | line source |
|---|---|
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
1 // hinged box with a filament hinge or a latch at the back and hinged |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
2 // latches on any of the other sides. sized by its inner dimensions, e.g. |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
3 // for standing notepad paper. |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
4 // x runs front (-x) to back (+x), y right (-y) to left (+y) seen from the |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
5 // front, z up. |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
6 // the preview turns the model 90 degrees so the front faces -y. |
| 0 | 7 |
| 8 /* [part selection] */ | |
| 9 // part to show or export | |
| 10 part = "all"; // [all, body, lid, latch] | |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
11 // cut away the +x half in preview, the right half seen from the front |
| 1 | 12 preview_cut = false; |
| 6 | 13 // show a content mockup in each cell in the assembly view |
| 14 preview_content = false; | |
| 0 | 15 // show the filament pins and latch bar in the assembly view |
| 16 preview_hardware = false; | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
17 // lid opening in percent in the assembly view |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
18 preview_lid_open = 0; // [0:1:100] |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
19 // opening angle of all latches in the assembly view |
| 0 | 20 preview_latch_angle = 0; // [0:1:75] |
| 21 | |
| 22 /* [box] */ | |
| 6 | 23 // inner size front to back, of one cell |
| 24 inner_depth = 92; // [10:.1:300] | |
| 25 // inner size left to right of one cell | |
| 26 inner_width = 92; // [10:.1:300] | |
| 0 | 27 // inner height, floor to lid ceiling |
| 6 | 28 inner_height = 92; // [10:.1:300] |
| 0 | 29 // share of the inner height taken by the body |
| 2 | 30 body_ratio = .85; // [.1:.01:.99] |
| 0 | 31 // radius of the vertical outer edges |
| 32 edge_radius = 2; // [0:.1:10] | |
| 6 | 33 |
| 34 /* [dividers] */ | |
| 35 // number of cells left to right. inner_width is the width of one cell | |
| 36 columns = 1; // [1:1:10] | |
| 37 // number of cells front to back. inner_depth is the depth of one cell | |
| 38 rows = 1; // [1:1:10] | |
| 39 // divider wall thickness in extrusions | |
| 40 divider_lines = 2; // [1:1:10] | |
| 41 | |
| 42 /* [content] */ | |
| 43 // content size front to back, for the preview mockup and the lid sweep check. at most the cell depth | |
| 44 content_depth = 90; // [1:.1:300] | |
| 45 // content size left to right, for the preview mockup. at most the cell width | |
| 46 content_width = 90; // [1:.1:300] | |
| 47 // content height, for the preview mockup and the lid sweep check. at most the inner height | |
| 48 content_height = 90; // [1:.1:300] | |
| 0 | 49 |
| 50 /* [walls] */ | |
| 51 // wall thickness in extrusions | |
| 52 wall_lines = 4; // [2:1:10] | |
| 53 // lip thickness in extrusions: the inner part of the body wall, raised into the lid | |
| 54 lip_lines = 2; // [1:1:8] | |
| 55 // lip height in layers | |
| 56 lip_layers = 4; // [1:1:20] | |
| 57 // floor and lid top thickness in layers | |
| 58 floor_layers = 6; // [2:1:20] | |
| 1 | 59 // chamfer height in layers at the build plate edges of body and lid. each layer steps in by one layer height |
| 60 chamfer_layers = 3; // [0:1:10] | |
| 0 | 61 |
| 62 /* [hinge] */ | |
| 63 // diameter of the filament used as hinge pin | |
| 7 | 64 filament_diameter = 1.85; // [1:.05:3] |
| 0 | 65 // number of hinge knuckles. the body gets the outer ones |
| 66 hinge_knuckles = 5; // [3:2:15] | |
| 67 // knuckle wall around the pin hole, in extrusions | |
| 68 hinge_lines = 3; // [2:1:8] | |
| 69 | |
| 70 /* [latch] */ | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
71 // back of the box: the hinge, or a latch for a removable lid |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
72 back_side = "hinge"; // [hinge, latch] |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
73 // latch on the front |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
74 latch_front = true; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
75 // latch on the left side, seen from the front |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
76 latch_left = false; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
77 // latch on the right side, seen from the front |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
78 latch_right = false; |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
79 // latch shape: a plate in front of the knuckles joining knuckle and hook, or a solid block between the bar knuckles |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
80 latch_style = "plate"; // [plate, block] |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
81 // latch width, the same for all latches |
| 0 | 82 latch_width = 20; // [8:1:100] |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
83 // share of the latch width taken by the middle knuckle that carries the latch. the outer knuckles share the rest |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
84 latch_middle_ratio = .33; // [.1:.01:.9] |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
85 // plate style: plate across the full latch width, printed flat. otherwise only as wide as the middle knuckle, printed standing on its side |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
86 latch_plate_full = true; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
87 // latch plate thickness in layers. a plate printed on its side is rounded up to whole extrusions |
| 0 | 88 latch_layers = 8; // [4:1:20] |
| 89 // radial overlap the hook tip has to pass at the filament bar. 0 for a free swinging latch | |
| 90 latch_detent = .3; // [0:.05:.7] | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
91 // grip length below the hook: the plate's grip tab, or the block's extension |
| 0 | 92 latch_grip = 5; // [0:.5:20] |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
93 // hook wall around the filament bar, in extrusions |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
94 latch_hook_lines = 3; // [2:1:8] |
| 0 | 95 |
| 96 /* [print settings] */ | |
| 97 line_width = .4; // [0:.01:1] | |
| 98 layer_height = .2; // [0:.01:.5] | |
| 99 clearance = .1; // [0:.01:.5] | |
| 100 | |
| 101 module dummy() {} | |
| 102 | |
| 103 epsilon = .001; | |
| 104 $fn = $preview ? 60 : 180; | |
| 105 | |
| 106 lw = line_width; | |
| 107 lh = layer_height; | |
| 108 cl = clearance; | |
| 109 | |
| 110 // walls | |
| 111 wall_t = wall_lines*lw; | |
| 112 // lid wall part that overlaps the lip from outside | |
| 113 skirt_t = (wall_lines - lip_lines)*lw; | |
| 114 lip_h = lip_layers*lh; | |
| 115 floor_t = floor_layers*lh; | |
| 1 | 116 chamfer_h = chamfer_layers*lh; |
| 6 | 117 // dividers and the total inner size over all cells |
| 118 div_t = divider_lines*lw; | |
| 119 in_x = rows*inner_depth + (rows - 1)*div_t; | |
| 120 in_y = columns*inner_width + (columns - 1)*div_t; | |
| 121 out_x = in_x + 2*wall_t; | |
| 122 out_y = in_y + 2*wall_t; | |
| 0 | 123 edge_r = min(edge_radius, min(out_x, out_y)/2 - epsilon); |
| 124 | |
| 125 // knuckles, shared by hinge and latch | |
| 126 pin_d = filament_diameter + 2*cl; | |
| 127 knuckle_r = pin_d/2 + hinge_lines*lw; | |
| 128 // axis distance from the outer wall face | |
| 129 knuckle_u = knuckle_r + 2*cl; | |
| 130 // axial gap between knuckles | |
| 131 knuckle_gap = 2*cl; | |
| 132 | |
| 2 | 133 // heights. the seam between body and lid sits on a layer boundary. |
| 134 // the lid needs room for the wall around the latch pin hole, which sits | |
| 135 // one knuckle radius plus clearance above the seam, and for one layer of | |
| 136 // skirt wall above the recess over the lip. a body ratio that leaves less | |
| 137 // is lowered to the highest layer that fits | |
| 138 lid_min_h = max(2*knuckle_r + cl, floor_t + lip_h + 2*lh); | |
| 139 body_ih_max = floor((inner_height + floor_t - lid_min_h)/lh)*lh; | |
| 140 body_ih_req = round(body_ratio*inner_height/lh)*lh; | |
| 141 body_ih = min(body_ih_req, body_ih_max); | |
| 142 seam_z = floor_t + body_ih; | |
| 143 top_z = floor_t + inner_height + floor_t; | |
| 144 lid_h = top_z - seam_z; | |
| 145 | |
| 0 | 146 // hinge |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
147 back_hinge = back_side == "hinge"; |
| 0 | 148 hinge_x = out_x/2 + knuckle_u; |
| 149 hinge_span = out_y - 2*edge_r; | |
| 150 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; | |
| 151 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
152 // sides that can take a latch: front, back, left, right. side_a turns the |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
153 // front to that side, side_d is the distance of its face from the centre, |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
154 // side_span the length of the face between the edge roundings |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
155 side_name = ["front", "back", "left", "right"]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
156 side_a = [0, 180, -90, 90]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
157 side_d = [out_x/2, out_x/2, out_y/2, out_y/2]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
158 side_span = [out_y - 2*edge_r, out_y - 2*edge_r, out_x - 2*edge_r, out_x - 2*edge_r]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
159 side_on = [latch_front, !back_hinge, latch_left, latch_right]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
160 latch_sides = [for (i = [0:3]) if (side_on[i]) i]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
161 |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
162 // latch. the latch hangs from lid knuckles and its hook wraps around a |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
163 // filament bar held by body knuckles straight below the latch axis. the |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
164 // latch hardware is modelled in a face frame: u runs outward from the |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
165 // face, y along it, z up. all latches have the same width; one wider than |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
166 // the narrowest latched face is narrowed to it |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
167 latch_w = min(concat([latch_width], [for (i = latch_sides) side_span[i]])); |
| 0 | 168 latch_z = seam_z + knuckle_r + cl; |
| 169 bar_z = seam_z - cl - knuckle_r; | |
| 170 bar_r = filament_diameter/2; | |
| 171 // distance between flap axis and bar axis | |
| 172 bar_h = latch_z - bar_z; | |
| 173 hook_ri = bar_r + cl; | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
174 hook_ro = hook_ri + latch_hook_lines*lw; |
| 0 | 175 // outer radius of the bar minus radius of the hook tip, both around the |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
176 // latch axis, for a hook reaching angle b past the bottom of the bar |
| 0 | 177 function _detent(b) = |
| 178 bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]); | |
| 179 // bisection for the angle that gives latch_detent | |
| 180 function _hook_angle(lo, hi, n=40) = | |
| 181 n == 0 ? (lo + hi)/2 : | |
| 182 let(m = (lo + hi)/2) | |
| 183 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); | |
| 184 hook_a = _hook_angle(0, 90); | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
185 |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
186 // strings in v joined with sep between them |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
187 function _join(v, sep="", i=0) = |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
188 i >= len(v) ? "" : str(i > 0 ? sep : "", v[i], _join(v, sep, i + 1)); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
189 |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
190 // knuckle slots across the latch width: the middle one carries the latch, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
191 // the outer ones have a lid knuckle above and a body knuckle below. a |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
192 // ratio that leaves a slot narrower than 2 extrusions is clamped |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
193 latch_span = latch_w - 2*knuckle_gap; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
194 slot_min = 2*lw; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
195 latch_ratio = min(max(latch_middle_ratio, slot_min/latch_span), 1 - 2*slot_min/latch_span); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
196 latch_mid = latch_ratio*latch_span; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
197 latch_outer = (latch_span - latch_mid)/2; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
198 // y start of the two outer latch slots |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
199 latch_outer_y0 = [-latch_w/2, latch_mid/2 + knuckle_gap]; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
200 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
201 // the latch prints standing on its side, its profile in the print plane, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
202 // unless it is a plate across the full latch width |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
203 latch_block = latch_style == "block"; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
204 latch_on_side = latch_block || !latch_plate_full; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
205 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
206 // plate style. on its side, the thickness is rounded up to whole |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
207 // extrusions; the small margin keeps an exact multiple from rounding up |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
208 plate_w = latch_on_side ? latch_mid : latch_w; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
209 plate_lines = ceil(latch_layers*lh/lw - .001); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
210 plate_t = latch_on_side ? plate_lines*lw : latch_layers*lh; |
| 0 | 211 plate_u = knuckle_u + knuckle_r + 2*cl; |
| 212 plate_bz = bar_z - hook_ro - latch_grip; | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
213 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
214 // block style: the profile of the body knuckles, reaching from the latch |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
215 // knuckle down past the hook by latch_grip. blk_r is the radius of the |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
216 // rounded front, blk_back the gap between back face and wall, blk_cz the |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
217 // centre of the lowest round and blk_bz the bottom end of the back face |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
218 blk_r = max(knuckle_r, hook_ro); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
219 blk_back = 2*cl; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
220 blk_cz = bar_z - latch_grip; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
221 blk_bz = blk_cz - blk_r - (knuckle_u - blk_back); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
222 // fingernail notch in the back face at the bottom edge: 3 extrusions |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
223 // deep, 8 extrusions high, kept 2 extrusions below the hook |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
224 nail_d = 3*lw; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
225 nail_h = min(8*lw, bar_z - hook_ro - 2*lw - blk_bz); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
226 |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
227 // how far the latch reaches out from the face |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
228 latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; |
| 0 | 229 |
| 230 assert(_detent(90) > latch_detent, "latch_detent too large for the filament bar"); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
231 assert(!back_hinge || knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); |
| 2 | 232 assert(body_ih > 0, "inner height too low for the lid"); |
| 1 | 233 assert(chamfer_h <= floor_t, "chamfer higher than the floor"); |
| 0 | 234 |
| 6 | 235 // cell centres: x for row i from the front, y for column j from the left |
| 236 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t); | |
| 237 function _cell_y(j) = -in_y/2 + inner_width/2 + j*(inner_width + div_t); | |
| 238 | |
| 239 // content, clamped to one cell | |
| 240 cont_x = min(content_depth, inner_depth); | |
| 241 cont_y = min(content_width, inner_width); | |
| 242 cont_z = min(content_height, inner_height); | |
| 243 | |
| 244 // lid sweep over the content centred in the front row, the one furthest | |
| 245 // from the hinge: radius of the lowest lid ceiling point over the content | |
| 246 // minus radius of the content's front top corner | |
| 0 | 247 sweep_margin = |
| 6 | 248 norm([hinge_x + in_x/2, lip_h + lh]) |
| 249 - norm([hinge_x - _cell_x(0) + cont_x/2, floor_t + cont_z - seam_z]); | |
| 0 | 250 |
| 251 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions"); | |
| 252 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm"); | |
| 6 | 253 if (columns > 1 || rows > 1) |
| 254 echo("divider thickness", div_t, "mm", divider_lines, "extrusions"); | |
| 255 echo("inner size", in_x, in_y, inner_height, "mm"); | |
| 0 | 256 echo("outer size", out_x, out_y, top_z, "mm"); |
| 1 | 257 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers"); |
| 2 | 258 if (body_ih < body_ih_req) |
| 259 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", | |
| 260 body_ih/inner_height)); | |
| 261 echo("body height", seam_z, "mm, lid height", lid_h, "mm, body ratio", body_ih/inner_height); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
262 echo(str("back: ", back_side, ", latches: ", |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
263 len(latch_sides) == 0 ? "none" : _join([for (i = latch_sides) side_name[i]], ", "), |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
264 ", print ", len(latch_sides), len(latch_sides) == 1 ? " latch" : " latches")); |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
265 if (latch_w < latch_width) |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
266 echo(str("WARNING: latch_width ", latch_width, " is wider than the narrowest latched face, using ", |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
267 latch_w)); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
268 if (latch_ratio != latch_middle_ratio) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
269 echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
270 " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); |
| 0 | 271 echo("pin hole", pin_d, "mm, knuckle diameter", 2*knuckle_r, "mm"); |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
272 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
273 echo("hinge knuckle length", knuckle_l, "mm"); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
274 echo("latch knuckle length: middle", latch_mid, "mm, outer", latch_outer, "mm"); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
275 echo(str("latch style ", latch_style, ", printed ", latch_on_side ? "on its side" : "flat")); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
276 if (latch_block) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
277 echo("latch block length below the hook", latch_grip, "mm"); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
278 if (nail_h > 0) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
279 echo("fingernail notch", nail_d, "mm deep, reaching", nail_h, "mm above the bottom edge"); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
280 else |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
281 echo("WARNING: latch_grip too short for the fingernail notch"); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
282 } else if (latch_on_side) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
283 echo("latch plate thickness", plate_t, "mm", plate_lines, "extrusions, width", plate_w, "mm"); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
284 else |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
285 echo("latch plate thickness", plate_t, "mm", latch_layers, "layers, width", plate_w, "mm"); |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
286 echo("latch outer face", latch_front_u, "mm from the box face"); |
| 0 | 287 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); |
| 6 | 288 if (cont_x < content_depth) |
| 289 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); | |
| 290 if (cont_y < content_width) | |
| 291 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y)); | |
| 292 if (cont_z < content_height) | |
| 293 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", | |
| 294 cont_z)); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
295 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
296 echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); |
| 0 | 297 |
| 298 // rounded box outline, inset by d | |
| 299 module _outline(d) { | |
| 300 r = max(edge_r - d, 0); | |
| 301 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true); | |
| 302 } | |
| 303 | |
| 1 | 304 // outer box shape of height h, the bottom edge chamfered in steps of one |
| 305 // layer, each step inset by one layer height | |
| 306 module _block(h) { | |
| 307 for (i = [0:1:chamfer_layers - 1]) | |
| 308 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh); | |
| 309 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0); | |
| 310 } | |
| 311 | |
| 0 | 312 // extrude a 2d profile drawn in x/z between y0 and y1 |
| 313 module _yslab(y0, y1) { | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
314 translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0, convexity=4) children(); |
| 0 | 315 } |
| 316 | |
| 317 // frame with u outward from the back face | |
| 318 module _back() { | |
| 319 translate([out_x/2, 0, 0]) children(); | |
| 320 } | |
| 321 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
322 // face frame of side i: u outward from the face, y along it |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
323 module _side(i) { |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
324 rotate([0, 0, side_a[i]]) translate([-side_d[i], 0, 0]) mirror([1, 0, 0]) children(); |
| 0 | 325 } |
| 326 | |
| 327 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); | |
| 328 | |
| 329 module _hinge_pin() { | |
| 330 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0]) | |
| 331 cylinder(d=pin_d, h=out_y + 2, center=true); | |
| 332 } | |
| 333 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
334 // latch pin hole in the face frame |
| 0 | 335 module _latch_pin() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
336 translate([knuckle_u, 0, latch_z]) rotate([90, 0, 0]) |
| 4 | 337 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 338 } |
| 339 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
340 // bar hole in the face frame |
| 0 | 341 module _bar_pin() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
342 translate([knuckle_u, 0, bar_z]) rotate([90, 0, 0]) |
| 4 | 343 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 344 } |
| 345 | |
| 346 module body() { | |
| 6 | 347 // divider walls between the cells, reaching into the outer wall |
| 348 module _dividers() { | |
| 349 for (j = [1:1:columns - 1]) | |
| 350 translate([-in_x/2 - epsilon, _cell_y(j) - inner_width/2 - div_t]) | |
| 351 square([in_x + 2*epsilon, div_t]); | |
| 352 for (i = [1:1:rows - 1]) | |
| 353 translate([_cell_x(i) - inner_depth/2 - div_t, -in_y/2 - epsilon]) | |
| 354 square([div_t, in_y + 2*epsilon]); | |
| 355 } | |
| 356 | |
| 0 | 357 // knuckle at height z with a web down to the wall up to z1, chamfered |
| 358 // below for printing | |
| 359 module _knuckle(z, z1) { | |
| 360 hull() { | |
| 361 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 362 translate([-epsilon, z - knuckle_r - knuckle_u]) | |
| 363 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 difference() { | |
| 368 union() { | |
| 1 | 369 _block(seam_z); |
| 0 | 370 translate([0, 0, seam_z - epsilon]) |
| 371 linear_extrude(lip_h + epsilon) | |
| 372 difference() { | |
| 373 _outline(skirt_t + cl); | |
| 374 _outline(wall_t); | |
| 375 } | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
376 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
377 for (i = [0:2:hinge_knuckles - 1]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
378 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
379 _knuckle(seam_z, seam_z - cl); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
380 for (i = latch_sides, y0 = latch_outer_y0) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
381 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); |
| 0 | 382 } |
| 383 translate([0, 0, floor_t]) linear_extrude(top_z) _outline(wall_t); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
384 if (back_hinge) _hinge_pin(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
385 for (i = latch_sides) _side(i) _bar_pin(); |
| 0 | 386 } |
| 6 | 387 // dividers from the floor to the top of the lip |
| 388 translate([0, 0, floor_t - epsilon]) | |
| 389 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers(); | |
| 0 | 390 } |
| 391 | |
| 392 // in assembly position, closed | |
| 393 module lid() { | |
| 394 // knuckle at height z with a web up to the wall from z0, chamfered | |
| 6 | 395 // towards the lid top for printing upside down. the web joins the wall |
| 396 // through a strip one epsilon thick just inside the outer face, so it | |
| 397 // stays out of the body wall below the seam. where the web reaches the | |
| 398 // edge chamfer at the lid top, a block fills the chamfer. a knuckle that | |
| 399 // would reach past the lid top is cut off there and stands on the print | |
| 400 // bed | |
| 0 | 401 module _knuckle(z, z0) { |
| 6 | 402 web_z1 = z + knuckle_r + knuckle_u; |
| 403 fill_z0 = max(z0, top_z - chamfer_h); | |
| 2 | 404 intersection() { |
| 6 | 405 union() { |
| 406 hull() { | |
| 407 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 408 translate([-epsilon, z0]) square([epsilon, web_z1 - z0]); | |
| 409 } | |
| 410 if (web_z1 > fill_z0) | |
| 411 translate([-chamfer_h - epsilon, fill_z0]) | |
| 412 square([chamfer_h + epsilon, web_z1 - fill_z0]); | |
| 2 | 413 } |
| 6 | 414 translate([-epsilon - 1, z - knuckle_r - 1]) |
| 415 square([epsilon + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]); | |
| 0 | 416 } |
| 417 } | |
| 418 | |
| 419 difference() { | |
| 420 union() { | |
| 1 | 421 translate([0, 0, top_z]) mirror([0, 0, 1]) _block(lid_h); |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
422 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
423 for (i = [1:2:hinge_knuckles - 1]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
424 _back() _yslab(_knuckle_y0(i), _knuckle_y0(i) + knuckle_l) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
425 _knuckle(seam_z, seam_z + cl); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
426 for (i = latch_sides, y0 = latch_outer_y0) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
427 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); |
| 0 | 428 } |
| 429 translate([0, 0, seam_z - epsilon]) | |
| 430 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); | |
| 431 // recess over the lip, one layer higher than the lip | |
| 432 translate([0, 0, seam_z - epsilon]) | |
| 433 linear_extrude(lip_h + lh + epsilon) _outline(skirt_t); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
434 if (back_hinge) _hinge_pin(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
435 for (i = latch_sides) _side(i) _latch_pin(); |
| 0 | 436 } |
| 437 } | |
| 438 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
439 // in the face frame, closed. the plate style has a knuckle and a hook |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
440 // in the middle slot, joined by a plate in front of the outer knuckles. the |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
441 // block style is one solid profile across the middle slot |
| 0 | 442 module latch() { |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
443 tip_a = 270 - hook_a; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
444 axis = [knuckle_u, latch_z]; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
445 bar = [knuckle_u, bar_z]; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
446 // length of the hook tip line from the bar centre to past the back face |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
447 tip_l = (knuckle_u + 1)/max(abs(cos(tip_a)), .1); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
448 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
449 // sector of radius r from angle a0 to a1, counterclockwise |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
450 module _sector(r, a0, a1) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
451 polygon(concat([[0, 0]], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
452 [for (a = [a0:10:a1]) r*[cos(a), sin(a)]], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
453 [r*[cos(a1), sin(a1)]])); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
454 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
455 |
| 0 | 456 // hook around the bar, from the plate side down under the bar and |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
457 // hook_a degrees up its wall side |
| 0 | 458 module _hook() { |
| 459 difference() { | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
460 hull() { |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
461 translate([knuckle_u, bar_z]) circle(r=hook_ro); |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
462 translate([knuckle_u, bar_z - hook_ro]) |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
463 square([plate_u - knuckle_u + epsilon, hook_ro]); |
| 0 | 464 } |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
465 translate(bar) circle(r=hook_ri); |
| 0 | 466 // open wedge over the top and the wall side of the bar |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
467 translate(bar) _sector(2*hook_ro, 0, tip_a); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
468 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
469 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
470 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
471 module _plate() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
472 _yslab(-plate_w/2, plate_w/2) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
473 translate([plate_u, plate_bz]) square([plate_t, latch_z - plate_bz]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
474 _yslab(-latch_mid/2, latch_mid/2) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
475 hull() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
476 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
477 translate([plate_u, latch_z - knuckle_r]) square([plate_t, knuckle_r]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
478 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
479 _hook(); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
480 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
481 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
482 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
483 // profile of the block: rounded at the front, the back face flat along |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
484 // the wall, sloped at the bottom like the body knuckles |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
485 module _block() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
486 difference() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
487 intersection() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
488 hull() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
489 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
490 translate(bar) circle(r=blk_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
491 translate([knuckle_u, blk_cz]) circle(r=blk_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
492 translate([blk_back, blk_bz]) square([epsilon, latch_z - blk_bz]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
493 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
494 // keep the back face off the wall where the hook is larger |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
495 // than the knuckle |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
496 translate([blk_back, blk_bz - 1]) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
497 square([knuckle_u + blk_r + 1, latch_z + knuckle_r - blk_bz + 2]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
498 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
499 translate(bar) circle(r=hook_ri); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
500 // opening for the bar, leaving the knuckle ring and the front |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
501 // wall: from the knuckle down to the bar, front to the far side |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
502 // of the bar hole, and on the wall side down to the line of the |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
503 // hook tip face, which runs on through the bar centre to the |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
504 // back face |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
505 difference() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
506 polygon([ |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
507 bar, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
508 bar + tip_l*[cos(tip_a), sin(tip_a)], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
509 [-1, latch_z], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
510 [knuckle_u + hook_ri, latch_z], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
511 [knuckle_u + hook_ri, bar_z]]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
512 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
513 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
514 // fingernail notch |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
515 if (nail_h > 0) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
516 translate([blk_back - epsilon, blk_bz - epsilon]) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
517 square([nail_d + epsilon, nail_h + epsilon]); |
| 0 | 518 } |
| 519 } | |
| 520 | |
| 521 difference() { | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
522 if (latch_block) _yslab(-latch_mid/2, latch_mid/2) _block(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
523 else _plate(); |
| 0 | 524 _latch_pin(); |
| 525 } | |
| 526 } | |
| 527 | |
| 6 | 528 // content block centred in each cell |
| 529 module _content() { | |
| 0 | 530 color("white", .6) |
| 6 | 531 for (i = [0:1:rows - 1], j = [0:1:columns - 1]) |
| 532 translate([_cell_x(i) - cont_x/2, _cell_y(j) - cont_y/2, floor_t]) | |
| 533 cube([cont_x, cont_y, cont_z]); | |
| 0 | 534 } |
| 535 | |
| 536 // filament of length l along y at x, z | |
| 537 module _filament(x, z, l) { | |
| 538 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0]) | |
| 539 cylinder(d=filament_diameter, h=l, center=true); | |
| 540 } | |
| 541 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
542 // the lid turns about the hinge axis with the back hinge, otherwise it |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
543 // lifts straight up. in the face frame, a latch opens with its bottom |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
544 // swinging outward |
| 0 | 545 module _assembly() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
546 lid_a = back_hinge ? 1.8*preview_lid_open : 0; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
547 lid_lift = back_hinge ? 0 : preview_lid_open/100*seam_z; |
| 0 | 548 color("steelblue") body(); |
| 549 if (preview_hardware && $preview) { | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
550 if (back_hinge) _filament(hinge_x, seam_z, hinge_span); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
551 for (i = latch_sides) _side(i) _filament(knuckle_u, bar_z, latch_w); |
| 0 | 552 } |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
553 translate([hinge_x, 0, seam_z + lid_lift]) rotate([0, lid_a, 0]) |
| 0 | 554 translate([-hinge_x, 0, -seam_z]) { |
| 555 color("lightsteelblue") lid(); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
556 for (i = latch_sides) _side(i) { |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
557 if (preview_hardware && $preview) _filament(knuckle_u, latch_z, latch_w); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
558 translate([knuckle_u, 0, latch_z]) rotate([0, -preview_latch_angle, 0]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
559 translate([-knuckle_u, 0, -latch_z]) color("orange") latch(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
560 } |
| 0 | 561 } |
| 6 | 562 if (preview_content && $preview) _content(); |
| 0 | 563 } |
| 564 | |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
565 // in preview, turn the model so its front faces the default camera at -y, |
|
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
566 // and with preview_cut remove the +x half, the right half seen from the |
|
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
567 // front. exports stay unturned |
| 0 | 568 module part_view() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
569 cut_s = max(max(out_x, out_y)/2 + latch_front_u, hinge_x + knuckle_r, top_z) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
570 + (preview_lid_open > 0 ? (back_hinge ? out_x : seam_z) : 0) + 1; |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
571 if ($preview) |
| 0 | 572 difference() { |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
573 rotate([0, 0, 90]) children(); |
|
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
574 if (preview_cut) translate([0, -cut_s, -cut_s]) cube([cut_s, 2*cut_s, 2*cut_s]); |
| 0 | 575 } |
| 576 else | |
| 577 children(); | |
| 578 } | |
| 579 | |
| 580 module main() { | |
| 581 if (part == "all") | |
| 582 part_view() _assembly(); | |
| 583 else if (part == "body") | |
| 584 part_view() body(); | |
| 585 else if (part == "lid") | |
| 586 part_view() | |
| 587 if ($preview) lid(); | |
| 588 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid(); | |
| 589 else if (part == "latch") | |
| 590 part_view() | |
| 591 if ($preview) latch(); | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
592 // on its side: the width along z, standing on the print bed |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
593 else if (latch_on_side) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
594 translate([0, 0, latch_mid/2]) rotate([90, 0, 0]) |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
595 translate([-knuckle_u, 0, -latch_z]) latch(); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
596 // flat: the plate face on the print bed |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
597 else translate([-latch_z, 0, latch_front_u]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
598 rotate([0, 90, 0]) latch(); |
| 0 | 599 } |
| 600 | |
| 601 main(); | |
| 602 | |
| 603 function paramstring(prefix="", suffix="") = str( | |
| 604 prefix, | |
| 605 part == "all" ? "" : str(part, "_"), | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
606 part == "latch" ? |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
607 str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", |
| 6 | 608 columns > 1 || rows > 1 ? str("c", columns, "r", rows, "_") : "", |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
609 // latched sides, only when they differ from the front latch and back hinge |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
610 side_on == [true, false, false, false] ? "" : |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
611 str("l", _join([for (i = latch_sides) "fblr"[i]]), "_"), |
| 0 | 612 "w", inner_width, "d", inner_depth, "h", inner_height, |
| 2 | 613 "b", round(100*body_ih/inner_height), |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
614 // latch middle share, only when it differs from the default |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
615 round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)), |
| 0 | 616 "_lw", round(100*line_width), "lh", round(100*layer_height), |
| 617 suffix); | |
| 618 | |
| 619 echo(paramstring("hinged_box_")); |
