wobblyhead hg > 3dprints > hinged_box
annotate main.scad @ 11:7bef1d0cb914 default tip
updated defaults, added render shell script
| author | ark |
|---|---|
| date | 2026-11-18 02:35 +0100 |
| parents | a7a1b12fd6bf |
| children |
| 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; | |
| 11 | 105 // parts to export for printing, read by render_openscad.sh |
| 106 printable_parts = "body lid latch"; | |
| 0 | 107 |
| 108 lw = line_width; | |
| 109 lh = layer_height; | |
| 110 cl = clearance; | |
| 111 | |
| 112 // walls | |
| 113 wall_t = wall_lines*lw; | |
| 114 // lid wall part that overlaps the lip from outside | |
| 115 skirt_t = (wall_lines - lip_lines)*lw; | |
| 116 lip_h = lip_layers*lh; | |
| 117 floor_t = floor_layers*lh; | |
| 1 | 118 chamfer_h = chamfer_layers*lh; |
| 6 | 119 // dividers and the total inner size over all cells |
| 120 div_t = divider_lines*lw; | |
| 121 in_x = rows*inner_depth + (rows - 1)*div_t; | |
| 122 in_y = columns*inner_width + (columns - 1)*div_t; | |
| 123 out_x = in_x + 2*wall_t; | |
| 124 out_y = in_y + 2*wall_t; | |
| 0 | 125 edge_r = min(edge_radius, min(out_x, out_y)/2 - epsilon); |
| 126 | |
| 127 // knuckles, shared by hinge and latch | |
| 128 pin_d = filament_diameter + 2*cl; | |
| 129 knuckle_r = pin_d/2 + hinge_lines*lw; | |
| 130 // axis distance from the outer wall face | |
| 131 knuckle_u = knuckle_r + 2*cl; | |
| 132 // axial gap between knuckles | |
| 133 knuckle_gap = 2*cl; | |
| 134 | |
| 2 | 135 // heights. the seam between body and lid sits on a layer boundary. |
| 136 // the lid needs room for the wall around the latch pin hole, which sits | |
| 137 // one knuckle radius plus clearance above the seam, and for one layer of | |
| 138 // skirt wall above the recess over the lip. a body ratio that leaves less | |
| 139 // is lowered to the highest layer that fits | |
| 140 lid_min_h = max(2*knuckle_r + cl, floor_t + lip_h + 2*lh); | |
| 141 body_ih_max = floor((inner_height + floor_t - lid_min_h)/lh)*lh; | |
| 142 body_ih_req = round(body_ratio*inner_height/lh)*lh; | |
| 143 body_ih = min(body_ih_req, body_ih_max); | |
| 144 seam_z = floor_t + body_ih; | |
| 145 top_z = floor_t + inner_height + floor_t; | |
| 146 lid_h = top_z - seam_z; | |
| 147 | |
| 0 | 148 // hinge |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
149 back_hinge = back_side == "hinge"; |
| 0 | 150 hinge_x = out_x/2 + knuckle_u; |
| 151 hinge_span = out_y - 2*edge_r; | |
| 152 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles; | |
| 153 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
154 // 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
|
155 // 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
|
156 // 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
|
157 side_name = ["front", "back", "left", "right"]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
158 side_a = [0, 180, -90, 90]; |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
164 // 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
|
165 // 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
|
166 // 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
|
167 // 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
|
168 // 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
|
169 latch_w = min(concat([latch_width], [for (i = latch_sides) side_span[i]])); |
| 0 | 170 latch_z = seam_z + knuckle_r + cl; |
| 171 bar_z = seam_z - cl - knuckle_r; | |
| 172 bar_r = filament_diameter/2; | |
| 173 // distance between flap axis and bar axis | |
| 174 bar_h = latch_z - bar_z; | |
| 175 hook_ri = bar_r + cl; | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
176 hook_ro = hook_ri + latch_hook_lines*lw; |
| 0 | 177 // 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
|
178 // latch axis, for a hook reaching angle b past the bottom of the bar |
| 0 | 179 function _detent(b) = |
| 180 bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]); | |
| 181 // bisection for the angle that gives latch_detent | |
| 182 function _hook_angle(lo, hi, n=40) = | |
| 183 n == 0 ? (lo + hi)/2 : | |
| 184 let(m = (lo + hi)/2) | |
| 185 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1); | |
| 186 hook_a = _hook_angle(0, 90); | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
187 |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
188 // 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
|
189 function _join(v, sep="", i=0) = |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
190 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
|
191 |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
192 // 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
|
193 // 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
|
194 // 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
|
195 latch_span = latch_w - 2*knuckle_gap; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
196 slot_min = 2*lw; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
197 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
|
198 latch_mid = latch_ratio*latch_span; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
199 latch_outer = (latch_span - latch_mid)/2; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
200 // y start of the two outer latch slots |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
201 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
|
202 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
203 // 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
|
204 // 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
|
205 latch_block = latch_style == "block"; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
206 latch_on_side = latch_block || !latch_plate_full; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
207 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
208 // 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
|
209 // 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
|
210 plate_w = latch_on_side ? latch_mid : latch_w; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
211 plate_lines = ceil(latch_layers*lh/lw - .001); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
212 plate_t = latch_on_side ? plate_lines*lw : latch_layers*lh; |
| 0 | 213 plate_u = knuckle_u + knuckle_r + 2*cl; |
| 214 plate_bz = bar_z - hook_ro - latch_grip; | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
215 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
216 // 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
|
217 // 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
|
218 // 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
|
219 // 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
|
220 blk_r = max(knuckle_r, hook_ro); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
221 blk_back = 2*cl; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
222 blk_cz = bar_z - latch_grip; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
223 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
|
224 // 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
|
225 // 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
|
226 nail_d = 3*lw; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
227 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
|
228 |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
229 // 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
|
230 latch_front_u = latch_block ? knuckle_u + blk_r : plate_u + plate_t; |
| 0 | 231 |
| 232 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
|
233 assert(!back_hinge || knuckle_l > 2*lw, "hinge knuckles too short, reduce hinge_knuckles"); |
| 2 | 234 assert(body_ih > 0, "inner height too low for the lid"); |
| 1 | 235 assert(chamfer_h <= floor_t, "chamfer higher than the floor"); |
| 0 | 236 |
| 6 | 237 // cell centres: x for row i from the front, y for column j from the left |
| 238 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t); | |
| 239 function _cell_y(j) = -in_y/2 + inner_width/2 + j*(inner_width + div_t); | |
| 240 | |
| 241 // content, clamped to one cell | |
| 242 cont_x = min(content_depth, inner_depth); | |
| 243 cont_y = min(content_width, inner_width); | |
| 244 cont_z = min(content_height, inner_height); | |
| 245 | |
| 246 // lid sweep over the content centred in the front row, the one furthest | |
| 247 // from the hinge: radius of the lowest lid ceiling point over the content | |
| 248 // minus radius of the content's front top corner | |
| 0 | 249 sweep_margin = |
| 6 | 250 norm([hinge_x + in_x/2, lip_h + lh]) |
| 251 - norm([hinge_x - _cell_x(0) + cont_x/2, floor_t + cont_z - seam_z]); | |
| 0 | 252 |
| 253 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions"); | |
| 254 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm"); | |
| 6 | 255 if (columns > 1 || rows > 1) |
| 256 echo("divider thickness", div_t, "mm", divider_lines, "extrusions"); | |
| 257 echo("inner size", in_x, in_y, inner_height, "mm"); | |
| 0 | 258 echo("outer size", out_x, out_y, top_z, "mm"); |
| 1 | 259 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers"); |
| 2 | 260 if (body_ih < body_ih_req) |
| 261 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ", | |
| 262 body_ih/inner_height)); | |
| 263 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
|
264 echo(str("back: ", back_side, ", latches: ", |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
265 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
|
266 ", 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
|
267 if (latch_w < latch_width) |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
268 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
|
269 latch_w)); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
270 if (latch_ratio != latch_middle_ratio) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
271 echo(str("WARNING: latch_middle_ratio ", latch_middle_ratio, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
272 " leaves a latch knuckle narrower than 2 extrusions, using ", latch_ratio)); |
| 0 | 273 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
|
274 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
275 echo("hinge knuckle length", knuckle_l, "mm"); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
276 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
|
277 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
|
278 if (latch_block) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
279 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
|
280 if (nail_h > 0) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
281 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
|
282 else |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
283 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
|
284 } else if (latch_on_side) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
285 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
|
286 else |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
287 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
|
288 echo("latch outer face", latch_front_u, "mm from the box face"); |
| 0 | 289 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm"); |
| 6 | 290 if (cont_x < content_depth) |
| 291 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x)); | |
| 292 if (cont_y < content_width) | |
| 293 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y)); | |
| 294 if (cont_z < content_height) | |
| 295 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ", | |
| 296 cont_z)); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
297 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
298 echo("lid sweep clearance over the content in the front row", sweep_margin, "mm"); |
| 0 | 299 |
| 300 // rounded box outline, inset by d | |
| 301 module _outline(d) { | |
| 302 r = max(edge_r - d, 0); | |
| 303 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true); | |
| 304 } | |
| 305 | |
| 1 | 306 // outer box shape of height h, the bottom edge chamfered in steps of one |
| 307 // layer, each step inset by one layer height | |
| 308 module _block(h) { | |
| 309 for (i = [0:1:chamfer_layers - 1]) | |
| 310 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh); | |
| 311 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0); | |
| 312 } | |
| 313 | |
| 0 | 314 // extrude a 2d profile drawn in x/z between y0 and y1 |
| 315 module _yslab(y0, y1) { | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
316 translate([0, y1, 0]) rotate([90, 0, 0]) linear_extrude(y1 - y0, convexity=4) children(); |
| 0 | 317 } |
| 318 | |
| 319 // frame with u outward from the back face | |
| 320 module _back() { | |
| 321 translate([out_x/2, 0, 0]) children(); | |
| 322 } | |
| 323 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
324 // 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
|
325 module _side(i) { |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
326 rotate([0, 0, side_a[i]]) translate([-side_d[i], 0, 0]) mirror([1, 0, 0]) children(); |
| 0 | 327 } |
| 328 | |
| 329 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap); | |
| 330 | |
| 331 module _hinge_pin() { | |
| 332 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0]) | |
| 333 cylinder(d=pin_d, h=out_y + 2, center=true); | |
| 334 } | |
| 335 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
336 // latch pin hole in the face frame |
| 0 | 337 module _latch_pin() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
338 translate([knuckle_u, 0, latch_z]) rotate([90, 0, 0]) |
| 4 | 339 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 340 } |
| 341 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
342 // bar hole in the face frame |
| 0 | 343 module _bar_pin() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
344 translate([knuckle_u, 0, bar_z]) rotate([90, 0, 0]) |
| 4 | 345 cylinder(d=pin_d, h=latch_w + 2, center=true); |
| 0 | 346 } |
| 347 | |
| 348 module body() { | |
| 6 | 349 // divider walls between the cells, reaching into the outer wall |
| 350 module _dividers() { | |
| 351 for (j = [1:1:columns - 1]) | |
| 352 translate([-in_x/2 - epsilon, _cell_y(j) - inner_width/2 - div_t]) | |
| 353 square([in_x + 2*epsilon, div_t]); | |
| 354 for (i = [1:1:rows - 1]) | |
| 355 translate([_cell_x(i) - inner_depth/2 - div_t, -in_y/2 - epsilon]) | |
| 356 square([div_t, in_y + 2*epsilon]); | |
| 357 } | |
| 358 | |
| 0 | 359 // knuckle at height z with a web down to the wall up to z1, chamfered |
| 360 // below for printing | |
| 361 module _knuckle(z, z1) { | |
| 362 hull() { | |
| 363 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 364 translate([-epsilon, z - knuckle_r - knuckle_u]) | |
| 365 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]); | |
| 366 } | |
| 367 } | |
| 368 | |
| 369 difference() { | |
| 370 union() { | |
| 1 | 371 _block(seam_z); |
| 0 | 372 translate([0, 0, seam_z - epsilon]) |
| 373 linear_extrude(lip_h + epsilon) | |
| 374 difference() { | |
| 375 _outline(skirt_t + cl); | |
| 376 _outline(wall_t); | |
| 377 } | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
378 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
379 for (i = [0:2:hinge_knuckles - 1]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
380 _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
|
381 _knuckle(seam_z, seam_z - cl); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
382 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
|
383 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(bar_z, bar_z + knuckle_r); |
| 0 | 384 } |
| 385 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
|
386 if (back_hinge) _hinge_pin(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
387 for (i = latch_sides) _side(i) _bar_pin(); |
| 0 | 388 } |
| 6 | 389 // dividers from the floor to the top of the lip |
| 390 translate([0, 0, floor_t - epsilon]) | |
| 391 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers(); | |
| 0 | 392 } |
| 393 | |
| 394 // in assembly position, closed | |
| 395 module lid() { | |
| 396 // knuckle at height z with a web up to the wall from z0, chamfered | |
| 6 | 397 // towards the lid top for printing upside down. the web joins the wall |
| 398 // through a strip one epsilon thick just inside the outer face, so it | |
| 399 // stays out of the body wall below the seam. where the web reaches the | |
| 400 // edge chamfer at the lid top, a block fills the chamfer. a knuckle that | |
| 401 // would reach past the lid top is cut off there and stands on the print | |
| 402 // bed | |
| 0 | 403 module _knuckle(z, z0) { |
| 6 | 404 web_z1 = z + knuckle_r + knuckle_u; |
| 405 fill_z0 = max(z0, top_z - chamfer_h); | |
| 2 | 406 intersection() { |
| 6 | 407 union() { |
| 408 hull() { | |
| 409 translate([knuckle_u, z]) circle(r=knuckle_r); | |
| 410 translate([-epsilon, z0]) square([epsilon, web_z1 - z0]); | |
| 411 } | |
| 412 if (web_z1 > fill_z0) | |
| 413 translate([-chamfer_h - epsilon, fill_z0]) | |
| 414 square([chamfer_h + epsilon, web_z1 - fill_z0]); | |
| 2 | 415 } |
| 6 | 416 translate([-epsilon - 1, z - knuckle_r - 1]) |
| 417 square([epsilon + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]); | |
| 0 | 418 } |
| 419 } | |
| 420 | |
| 421 difference() { | |
| 422 union() { | |
| 1 | 423 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
|
424 if (back_hinge) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
425 for (i = [1:2:hinge_knuckles - 1]) |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
426 _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
|
427 _knuckle(seam_z, seam_z + cl); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
428 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
|
429 _side(i) _yslab(y0, y0 + latch_outer) _knuckle(latch_z, seam_z + cl); |
| 0 | 430 } |
| 431 translate([0, 0, seam_z - epsilon]) | |
| 432 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t); | |
| 433 // recess over the lip, one layer higher than the lip | |
| 434 translate([0, 0, seam_z - epsilon]) | |
| 435 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
|
436 if (back_hinge) _hinge_pin(); |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
437 for (i = latch_sides) _side(i) _latch_pin(); |
| 0 | 438 } |
| 439 } | |
| 440 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
441 // 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
|
442 // 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
|
443 // block style is one solid profile across the middle slot |
| 0 | 444 module latch() { |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
445 tip_a = 270 - hook_a; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
446 axis = [knuckle_u, latch_z]; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
447 bar = [knuckle_u, bar_z]; |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
448 // 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
|
449 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
|
450 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
451 // 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
|
452 module _sector(r, a0, a1) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
453 polygon(concat([[0, 0]], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
454 [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
|
455 [r*[cos(a1), sin(a1)]])); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
456 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
457 |
| 0 | 458 // 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
|
459 // hook_a degrees up its wall side |
| 0 | 460 module _hook() { |
| 461 difference() { | |
|
5
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
462 hull() { |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
463 translate([knuckle_u, bar_z]) circle(r=hook_ro); |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
464 translate([knuckle_u, bar_z - hook_ro]) |
|
fdd022a1bfb1
reworked latch hook reinforcement, now a simple line count
ark
parents:
4
diff
changeset
|
465 square([plate_u - knuckle_u + epsilon, hook_ro]); |
| 0 | 466 } |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
467 translate(bar) circle(r=hook_ri); |
| 0 | 468 // 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
|
469 translate(bar) _sector(2*hook_ro, 0, tip_a); |
|
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 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
472 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
473 module _plate() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
474 _yslab(-plate_w/2, plate_w/2) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
475 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
|
476 _yslab(-latch_mid/2, latch_mid/2) { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
477 hull() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
478 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
479 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
|
480 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
481 _hook(); |
|
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 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
484 |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
485 // 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
|
486 // 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
|
487 module _block() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
488 difference() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
489 intersection() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
490 hull() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
491 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
492 translate(bar) circle(r=blk_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
493 translate([knuckle_u, blk_cz]) circle(r=blk_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
494 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
|
495 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
496 // 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
|
497 // than the knuckle |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
498 translate([blk_back, blk_bz - 1]) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
499 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
|
500 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
501 translate(bar) circle(r=hook_ri); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
502 // 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
|
503 // 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
|
504 // 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
|
505 // 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
|
506 // back face |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
507 difference() { |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
508 polygon([ |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
509 bar, |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
510 bar + tip_l*[cos(tip_a), sin(tip_a)], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
511 [-1, latch_z], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
512 [knuckle_u + hook_ri, latch_z], |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
513 [knuckle_u + hook_ri, bar_z]]); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
514 translate(axis) circle(r=knuckle_r); |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
515 } |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
516 // fingernail notch |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
517 if (nail_h > 0) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
518 translate([blk_back - epsilon, blk_bz - epsilon]) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
519 square([nail_d + epsilon, nail_h + epsilon]); |
| 0 | 520 } |
| 521 } | |
| 522 | |
| 523 difference() { | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
524 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
|
525 else _plate(); |
| 0 | 526 _latch_pin(); |
| 527 } | |
| 528 } | |
| 529 | |
| 6 | 530 // content block centred in each cell |
| 531 module _content() { | |
| 0 | 532 color("white", .6) |
| 6 | 533 for (i = [0:1:rows - 1], j = [0:1:columns - 1]) |
| 534 translate([_cell_x(i) - cont_x/2, _cell_y(j) - cont_y/2, floor_t]) | |
| 535 cube([cont_x, cont_y, cont_z]); | |
| 0 | 536 } |
| 537 | |
| 538 // filament of length l along y at x, z | |
| 539 module _filament(x, z, l) { | |
| 540 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0]) | |
| 541 cylinder(d=filament_diameter, h=l, center=true); | |
| 542 } | |
| 543 | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
544 // 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
|
545 // 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
|
546 // swinging outward |
| 0 | 547 module _assembly() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
548 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
|
549 lid_lift = back_hinge ? 0 : preview_lid_open/100*seam_z; |
| 0 | 550 color("steelblue") body(); |
| 551 if (preview_hardware && $preview) { | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
552 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
|
553 for (i = latch_sides) _side(i) _filament(knuckle_u, bar_z, latch_w); |
| 0 | 554 } |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
555 translate([hinge_x, 0, seam_z + lid_lift]) rotate([0, lid_a, 0]) |
| 0 | 556 translate([-hinge_x, 0, -seam_z]) { |
| 557 color("lightsteelblue") lid(); | |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
558 for (i = latch_sides) _side(i) { |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 } |
| 0 | 563 } |
| 6 | 564 if (preview_content && $preview) _content(); |
| 0 | 565 } |
| 566 | |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
567 // 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
|
568 // 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
|
569 // front. exports stay unturned |
| 0 | 570 module part_view() { |
|
10
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
571 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
|
572 + (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
|
573 if ($preview) |
| 0 | 574 difference() { |
|
9
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
575 rotate([0, 0, 90]) children(); |
|
4b89f95689a8
preview: turn the model so the front faces the default camera
ark
parents:
8
diff
changeset
|
576 if (preview_cut) translate([0, -cut_s, -cut_s]) cube([cut_s, 2*cut_s, 2*cut_s]); |
| 0 | 577 } |
| 578 else | |
| 579 children(); | |
| 580 } | |
| 581 | |
| 582 module main() { | |
| 583 if (part == "all") | |
| 584 part_view() _assembly(); | |
| 585 else if (part == "body") | |
| 586 part_view() body(); | |
| 587 else if (part == "lid") | |
| 588 part_view() | |
| 589 if ($preview) lid(); | |
| 590 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid(); | |
| 591 else if (part == "latch") | |
| 592 part_view() | |
| 593 if ($preview) latch(); | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
594 // 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
|
595 else if (latch_on_side) |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
596 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
|
597 translate([-knuckle_u, 0, -latch_z]) latch(); |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
598 // 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
|
599 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
|
600 rotate([0, 90, 0]) latch(); |
| 0 | 601 } |
| 602 | |
| 603 main(); | |
| 604 | |
| 605 function paramstring(prefix="", suffix="") = str( | |
| 606 prefix, | |
| 607 part == "all" ? "" : str(part, "_"), | |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
608 part == "latch" ? |
|
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
609 str(latch_block ? "block" : latch_plate_full ? "plate" : "plate-middle", "_") : "", |
| 6 | 610 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
|
611 // 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
|
612 side_on == [true, false, false, false] ? "" : |
|
a7a1b12fd6bf
latch: latches on any side, back latch for a removable lid
ark
parents:
9
diff
changeset
|
613 str("l", _join([for (i = latch_sides) "fblr"[i]]), "_"), |
| 11 | 614 "w", round(10*inner_width), "d", round(10*inner_depth), "h", round(10*inner_height), |
| 2 | 615 "b", round(100*body_ih/inner_height), |
|
8
ac8f2ecb6c18
latch: block style, middle knuckle share, middle-width plate
ark
parents:
7
diff
changeset
|
616 // 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
|
617 round(100*latch_ratio) == 33 ? "" : str("lm", round(100*latch_ratio)), |
| 0 | 618 "_lw", round(100*line_width), "lh", round(100*layer_height), |
| 619 suffix); | |
| 620 | |
| 621 echo(paramstring("hinged_box_")); |
