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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
38eca1c6d879 initial
ark
parents:
diff changeset
7
38eca1c6d879 initial
ark
parents:
diff changeset
8 /* [part selection] */
38eca1c6d879 initial
ark
parents:
diff changeset
9 // part to show or export
38eca1c6d879 initial
ark
parents:
diff changeset
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
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
12 preview_cut = false;
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
13 // show a content mockup in each cell in the assembly view
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
14 preview_content = false;
0
38eca1c6d879 initial
ark
parents:
diff changeset
15 // show the filament pins and latch bar in the assembly view
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
20 preview_latch_angle = 0; // [0:1:75]
38eca1c6d879 initial
ark
parents:
diff changeset
21
38eca1c6d879 initial
ark
parents:
diff changeset
22 /* [box] */
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
23 // inner size front to back, of one cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
24 inner_depth = 92; // [10:.1:300]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
25 // inner size left to right of one cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
26 inner_width = 92; // [10:.1:300]
0
38eca1c6d879 initial
ark
parents:
diff changeset
27 // inner height, floor to lid ceiling
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
28 inner_height = 92; // [10:.1:300]
0
38eca1c6d879 initial
ark
parents:
diff changeset
29 // share of the inner height taken by the body
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
30 body_ratio = .85; // [.1:.01:.99]
0
38eca1c6d879 initial
ark
parents:
diff changeset
31 // radius of the vertical outer edges
38eca1c6d879 initial
ark
parents:
diff changeset
32 edge_radius = 2; // [0:.1:10]
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
33
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
34 /* [dividers] */
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
35 // number of cells left to right. inner_width is the width of one cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
36 columns = 1; // [1:1:10]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
37 // number of cells front to back. inner_depth is the depth of one cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
38 rows = 1; // [1:1:10]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
39 // divider wall thickness in extrusions
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
40 divider_lines = 2; // [1:1:10]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
41
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
42 /* [content] */
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
43 // content size front to back, for the preview mockup and the lid sweep check. at most the cell depth
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
44 content_depth = 90; // [1:.1:300]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
45 // content size left to right, for the preview mockup. at most the cell width
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
46 content_width = 90; // [1:.1:300]
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
47 // content height, for the preview mockup and the lid sweep check. at most the inner height
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
48 content_height = 90; // [1:.1:300]
0
38eca1c6d879 initial
ark
parents:
diff changeset
49
38eca1c6d879 initial
ark
parents:
diff changeset
50 /* [walls] */
38eca1c6d879 initial
ark
parents:
diff changeset
51 // wall thickness in extrusions
38eca1c6d879 initial
ark
parents:
diff changeset
52 wall_lines = 4; // [2:1:10]
38eca1c6d879 initial
ark
parents:
diff changeset
53 // lip thickness in extrusions: the inner part of the body wall, raised into the lid
38eca1c6d879 initial
ark
parents:
diff changeset
54 lip_lines = 2; // [1:1:8]
38eca1c6d879 initial
ark
parents:
diff changeset
55 // lip height in layers
38eca1c6d879 initial
ark
parents:
diff changeset
56 lip_layers = 4; // [1:1:20]
38eca1c6d879 initial
ark
parents:
diff changeset
57 // floor and lid top thickness in layers
38eca1c6d879 initial
ark
parents:
diff changeset
58 floor_layers = 6; // [2:1:20]
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
59 // chamfer height in layers at the build plate edges of body and lid. each layer steps in by one layer height
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
60 chamfer_layers = 3; // [0:1:10]
0
38eca1c6d879 initial
ark
parents:
diff changeset
61
38eca1c6d879 initial
ark
parents:
diff changeset
62 /* [hinge] */
38eca1c6d879 initial
ark
parents:
diff changeset
63 // diameter of the filament used as hinge pin
7
1933892bab51 adjusted default
ark
parents: 6
diff changeset
64 filament_diameter = 1.85; // [1:.05:3]
0
38eca1c6d879 initial
ark
parents:
diff changeset
65 // number of hinge knuckles. the body gets the outer ones
38eca1c6d879 initial
ark
parents:
diff changeset
66 hinge_knuckles = 5; // [3:2:15]
38eca1c6d879 initial
ark
parents:
diff changeset
67 // knuckle wall around the pin hole, in extrusions
38eca1c6d879 initial
ark
parents:
diff changeset
68 hinge_lines = 3; // [2:1:8]
38eca1c6d879 initial
ark
parents:
diff changeset
69
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
88 latch_layers = 8; // [4:1:20]
38eca1c6d879 initial
ark
parents:
diff changeset
89 // radial overlap the hook tip has to pass at the filament bar. 0 for a free swinging latch
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
95
38eca1c6d879 initial
ark
parents:
diff changeset
96 /* [print settings] */
38eca1c6d879 initial
ark
parents:
diff changeset
97 line_width = .4; // [0:.01:1]
38eca1c6d879 initial
ark
parents:
diff changeset
98 layer_height = .2; // [0:.01:.5]
38eca1c6d879 initial
ark
parents:
diff changeset
99 clearance = .1; // [0:.01:.5]
38eca1c6d879 initial
ark
parents:
diff changeset
100
38eca1c6d879 initial
ark
parents:
diff changeset
101 module dummy() {}
38eca1c6d879 initial
ark
parents:
diff changeset
102
38eca1c6d879 initial
ark
parents:
diff changeset
103 epsilon = .001;
38eca1c6d879 initial
ark
parents:
diff changeset
104 $fn = $preview ? 60 : 180;
38eca1c6d879 initial
ark
parents:
diff changeset
105
38eca1c6d879 initial
ark
parents:
diff changeset
106 lw = line_width;
38eca1c6d879 initial
ark
parents:
diff changeset
107 lh = layer_height;
38eca1c6d879 initial
ark
parents:
diff changeset
108 cl = clearance;
38eca1c6d879 initial
ark
parents:
diff changeset
109
38eca1c6d879 initial
ark
parents:
diff changeset
110 // walls
38eca1c6d879 initial
ark
parents:
diff changeset
111 wall_t = wall_lines*lw;
38eca1c6d879 initial
ark
parents:
diff changeset
112 // lid wall part that overlaps the lip from outside
38eca1c6d879 initial
ark
parents:
diff changeset
113 skirt_t = (wall_lines - lip_lines)*lw;
38eca1c6d879 initial
ark
parents:
diff changeset
114 lip_h = lip_layers*lh;
38eca1c6d879 initial
ark
parents:
diff changeset
115 floor_t = floor_layers*lh;
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
116 chamfer_h = chamfer_layers*lh;
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
117 // dividers and the total inner size over all cells
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
118 div_t = divider_lines*lw;
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
119 in_x = rows*inner_depth + (rows - 1)*div_t;
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
120 in_y = columns*inner_width + (columns - 1)*div_t;
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
121 out_x = in_x + 2*wall_t;
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
122 out_y = in_y + 2*wall_t;
0
38eca1c6d879 initial
ark
parents:
diff changeset
123 edge_r = min(edge_radius, min(out_x, out_y)/2 - epsilon);
38eca1c6d879 initial
ark
parents:
diff changeset
124
38eca1c6d879 initial
ark
parents:
diff changeset
125 // knuckles, shared by hinge and latch
38eca1c6d879 initial
ark
parents:
diff changeset
126 pin_d = filament_diameter + 2*cl;
38eca1c6d879 initial
ark
parents:
diff changeset
127 knuckle_r = pin_d/2 + hinge_lines*lw;
38eca1c6d879 initial
ark
parents:
diff changeset
128 // axis distance from the outer wall face
38eca1c6d879 initial
ark
parents:
diff changeset
129 knuckle_u = knuckle_r + 2*cl;
38eca1c6d879 initial
ark
parents:
diff changeset
130 // axial gap between knuckles
38eca1c6d879 initial
ark
parents:
diff changeset
131 knuckle_gap = 2*cl;
38eca1c6d879 initial
ark
parents:
diff changeset
132
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
133 // heights. the seam between body and lid sits on a layer boundary.
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
134 // the lid needs room for the wall around the latch pin hole, which sits
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
135 // one knuckle radius plus clearance above the seam, and for one layer of
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
136 // skirt wall above the recess over the lip. a body ratio that leaves less
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
137 // is lowered to the highest layer that fits
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
138 lid_min_h = max(2*knuckle_r + cl, floor_t + lip_h + 2*lh);
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
139 body_ih_max = floor((inner_height + floor_t - lid_min_h)/lh)*lh;
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
140 body_ih_req = round(body_ratio*inner_height/lh)*lh;
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
141 body_ih = min(body_ih_req, body_ih_max);
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
142 seam_z = floor_t + body_ih;
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
143 top_z = floor_t + inner_height + floor_t;
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
144 lid_h = top_z - seam_z;
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
145
0
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
148 hinge_x = out_x/2 + knuckle_u;
38eca1c6d879 initial
ark
parents:
diff changeset
149 hinge_span = out_y - 2*edge_r;
38eca1c6d879 initial
ark
parents:
diff changeset
150 knuckle_l = (hinge_span - (hinge_knuckles - 1)*knuckle_gap)/hinge_knuckles;
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
168 latch_z = seam_z + knuckle_r + cl;
38eca1c6d879 initial
ark
parents:
diff changeset
169 bar_z = seam_z - cl - knuckle_r;
38eca1c6d879 initial
ark
parents:
diff changeset
170 bar_r = filament_diameter/2;
38eca1c6d879 initial
ark
parents:
diff changeset
171 // distance between flap axis and bar axis
38eca1c6d879 initial
ark
parents:
diff changeset
172 bar_h = latch_z - bar_z;
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
177 function _detent(b) =
38eca1c6d879 initial
ark
parents:
diff changeset
178 bar_h + bar_r - norm([hook_ri*sin(b), bar_h + hook_ri*cos(b)]);
38eca1c6d879 initial
ark
parents:
diff changeset
179 // bisection for the angle that gives latch_detent
38eca1c6d879 initial
ark
parents:
diff changeset
180 function _hook_angle(lo, hi, n=40) =
38eca1c6d879 initial
ark
parents:
diff changeset
181 n == 0 ? (lo + hi)/2 :
38eca1c6d879 initial
ark
parents:
diff changeset
182 let(m = (lo + hi)/2)
38eca1c6d879 initial
ark
parents:
diff changeset
183 _detent(m) < latch_detent ? _hook_angle(m, hi, n - 1) : _hook_angle(lo, m, n - 1);
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
211 plate_u = knuckle_u + knuckle_r + 2*cl;
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
229
38eca1c6d879 initial
ark
parents:
diff changeset
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
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
232 assert(body_ih > 0, "inner height too low for the lid");
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
233 assert(chamfer_h <= floor_t, "chamfer higher than the floor");
0
38eca1c6d879 initial
ark
parents:
diff changeset
234
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
235 // cell centres: x for row i from the front, y for column j from the left
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
236 function _cell_x(i) = -in_x/2 + inner_depth/2 + i*(inner_depth + div_t);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
237 function _cell_y(j) = -in_y/2 + inner_width/2 + j*(inner_width + div_t);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
238
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
239 // content, clamped to one cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
240 cont_x = min(content_depth, inner_depth);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
241 cont_y = min(content_width, inner_width);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
242 cont_z = min(content_height, inner_height);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
243
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
244 // lid sweep over the content centred in the front row, the one furthest
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
245 // from the hinge: radius of the lowest lid ceiling point over the content
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
246 // minus radius of the content's front top corner
0
38eca1c6d879 initial
ark
parents:
diff changeset
247 sweep_margin =
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
248 norm([hinge_x + in_x/2, lip_h + lh])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
249 - norm([hinge_x - _cell_x(0) + cont_x/2, floor_t + cont_z - seam_z]);
0
38eca1c6d879 initial
ark
parents:
diff changeset
250
38eca1c6d879 initial
ark
parents:
diff changeset
251 echo("wall thickness", wall_t, "mm", wall_lines, "extrusions");
38eca1c6d879 initial
ark
parents:
diff changeset
252 echo("lip thickness", wall_t - skirt_t - cl, "mm, height", lip_h, "mm");
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
253 if (columns > 1 || rows > 1)
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
254 echo("divider thickness", div_t, "mm", divider_lines, "extrusions");
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
255 echo("inner size", in_x, in_y, inner_height, "mm");
0
38eca1c6d879 initial
ark
parents:
diff changeset
256 echo("outer size", out_x, out_y, top_z, "mm");
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
257 echo("chamfer", chamfer_h, "mm", chamfer_layers, "layers");
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
258 if (body_ih < body_ih_req)
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
259 echo(str("WARNING: body_ratio ", body_ratio, " leaves the lid too low, using ",
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
260 body_ih/inner_height));
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
287 echo("latch hook reaches", hook_a, "degrees past the bar bottom, detent", _detent(hook_a), "mm");
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
288 if (cont_x < content_depth)
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
289 echo(str("WARNING: content_depth ", content_depth, " is larger than the cell, using ", cont_x));
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
290 if (cont_y < content_width)
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
291 echo(str("WARNING: content_width ", content_width, " is larger than the cell, using ", cont_y));
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
292 if (cont_z < content_height)
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
293 echo(str("WARNING: content_height ", content_height, " is larger than the inner height, using ",
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
297
38eca1c6d879 initial
ark
parents:
diff changeset
298 // rounded box outline, inset by d
38eca1c6d879 initial
ark
parents:
diff changeset
299 module _outline(d) {
38eca1c6d879 initial
ark
parents:
diff changeset
300 r = max(edge_r - d, 0);
38eca1c6d879 initial
ark
parents:
diff changeset
301 offset(r=r) square([out_x - 2*d - 2*r, out_y - 2*d - 2*r], center=true);
38eca1c6d879 initial
ark
parents:
diff changeset
302 }
38eca1c6d879 initial
ark
parents:
diff changeset
303
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
304 // outer box shape of height h, the bottom edge chamfered in steps of one
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
305 // layer, each step inset by one layer height
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
306 module _block(h) {
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
307 for (i = [0:1:chamfer_layers - 1])
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
308 translate([0, 0, i*lh]) linear_extrude(lh + epsilon) _outline((chamfer_layers - i)*lh);
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
309 translate([0, 0, chamfer_h]) linear_extrude(h - chamfer_h) _outline(0);
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
310 }
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
311
0
38eca1c6d879 initial
ark
parents:
diff changeset
312 // extrude a 2d profile drawn in x/z between y0 and y1
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
315 }
38eca1c6d879 initial
ark
parents:
diff changeset
316
38eca1c6d879 initial
ark
parents:
diff changeset
317 // frame with u outward from the back face
38eca1c6d879 initial
ark
parents:
diff changeset
318 module _back() {
38eca1c6d879 initial
ark
parents:
diff changeset
319 translate([out_x/2, 0, 0]) children();
38eca1c6d879 initial
ark
parents:
diff changeset
320 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
325 }
38eca1c6d879 initial
ark
parents:
diff changeset
326
38eca1c6d879 initial
ark
parents:
diff changeset
327 function _knuckle_y0(i) = -hinge_span/2 + i*(knuckle_l + knuckle_gap);
38eca1c6d879 initial
ark
parents:
diff changeset
328
38eca1c6d879 initial
ark
parents:
diff changeset
329 module _hinge_pin() {
38eca1c6d879 initial
ark
parents:
diff changeset
330 translate([hinge_x, 0, seam_z]) rotate([90, 0, 0])
38eca1c6d879 initial
ark
parents:
diff changeset
331 cylinder(d=pin_d, h=out_y + 2, center=true);
38eca1c6d879 initial
ark
parents:
diff changeset
332 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
80122df4a6c5 reinforced latch hook
ark
parents: 2
diff changeset
337 cylinder(d=pin_d, h=latch_w + 2, center=true);
0
38eca1c6d879 initial
ark
parents:
diff changeset
338 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
80122df4a6c5 reinforced latch hook
ark
parents: 2
diff changeset
343 cylinder(d=pin_d, h=latch_w + 2, center=true);
0
38eca1c6d879 initial
ark
parents:
diff changeset
344 }
38eca1c6d879 initial
ark
parents:
diff changeset
345
38eca1c6d879 initial
ark
parents:
diff changeset
346 module body() {
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
347 // divider walls between the cells, reaching into the outer wall
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
348 module _dividers() {
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
349 for (j = [1:1:columns - 1])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
350 translate([-in_x/2 - epsilon, _cell_y(j) - inner_width/2 - div_t])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
351 square([in_x + 2*epsilon, div_t]);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
352 for (i = [1:1:rows - 1])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
353 translate([_cell_x(i) - inner_depth/2 - div_t, -in_y/2 - epsilon])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
354 square([div_t, in_y + 2*epsilon]);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
355 }
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
356
0
38eca1c6d879 initial
ark
parents:
diff changeset
357 // knuckle at height z with a web down to the wall up to z1, chamfered
38eca1c6d879 initial
ark
parents:
diff changeset
358 // below for printing
38eca1c6d879 initial
ark
parents:
diff changeset
359 module _knuckle(z, z1) {
38eca1c6d879 initial
ark
parents:
diff changeset
360 hull() {
38eca1c6d879 initial
ark
parents:
diff changeset
361 translate([knuckle_u, z]) circle(r=knuckle_r);
38eca1c6d879 initial
ark
parents:
diff changeset
362 translate([-epsilon, z - knuckle_r - knuckle_u])
38eca1c6d879 initial
ark
parents:
diff changeset
363 square([epsilon, z1 - (z - knuckle_r - knuckle_u)]);
38eca1c6d879 initial
ark
parents:
diff changeset
364 }
38eca1c6d879 initial
ark
parents:
diff changeset
365 }
38eca1c6d879 initial
ark
parents:
diff changeset
366
38eca1c6d879 initial
ark
parents:
diff changeset
367 difference() {
38eca1c6d879 initial
ark
parents:
diff changeset
368 union() {
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
369 _block(seam_z);
0
38eca1c6d879 initial
ark
parents:
diff changeset
370 translate([0, 0, seam_z - epsilon])
38eca1c6d879 initial
ark
parents:
diff changeset
371 linear_extrude(lip_h + epsilon)
38eca1c6d879 initial
ark
parents:
diff changeset
372 difference() {
38eca1c6d879 initial
ark
parents:
diff changeset
373 _outline(skirt_t + cl);
38eca1c6d879 initial
ark
parents:
diff changeset
374 _outline(wall_t);
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
382 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
386 }
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
387 // dividers from the floor to the top of the lip
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
388 translate([0, 0, floor_t - epsilon])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
389 linear_extrude(seam_z + lip_h - floor_t + epsilon) _dividers();
0
38eca1c6d879 initial
ark
parents:
diff changeset
390 }
38eca1c6d879 initial
ark
parents:
diff changeset
391
38eca1c6d879 initial
ark
parents:
diff changeset
392 // in assembly position, closed
38eca1c6d879 initial
ark
parents:
diff changeset
393 module lid() {
38eca1c6d879 initial
ark
parents:
diff changeset
394 // knuckle at height z with a web up to the wall from z0, chamfered
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
395 // towards the lid top for printing upside down. the web joins the wall
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
396 // through a strip one epsilon thick just inside the outer face, so it
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
397 // stays out of the body wall below the seam. where the web reaches the
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
398 // edge chamfer at the lid top, a block fills the chamfer. a knuckle that
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
399 // would reach past the lid top is cut off there and stands on the print
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
400 // bed
0
38eca1c6d879 initial
ark
parents:
diff changeset
401 module _knuckle(z, z0) {
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
402 web_z1 = z + knuckle_r + knuckle_u;
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
403 fill_z0 = max(z0, top_z - chamfer_h);
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
404 intersection() {
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
405 union() {
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
406 hull() {
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
407 translate([knuckle_u, z]) circle(r=knuckle_r);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
408 translate([-epsilon, z0]) square([epsilon, web_z1 - z0]);
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
409 }
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
410 if (web_z1 > fill_z0)
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
411 translate([-chamfer_h - epsilon, fill_z0])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
412 square([chamfer_h + epsilon, web_z1 - fill_z0]);
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
413 }
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
414 translate([-epsilon - 1, z - knuckle_r - 1])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
415 square([epsilon + knuckle_u + knuckle_r + 2, top_z - (z - knuckle_r - 1)]);
0
38eca1c6d879 initial
ark
parents:
diff changeset
416 }
38eca1c6d879 initial
ark
parents:
diff changeset
417 }
38eca1c6d879 initial
ark
parents:
diff changeset
418
38eca1c6d879 initial
ark
parents:
diff changeset
419 difference() {
38eca1c6d879 initial
ark
parents:
diff changeset
420 union() {
1
d17ae0060cba added chamfer to bottom of body and lid
ark
parents: 0
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
428 }
38eca1c6d879 initial
ark
parents:
diff changeset
429 translate([0, 0, seam_z - epsilon])
38eca1c6d879 initial
ark
parents:
diff changeset
430 linear_extrude(lid_h - floor_t + epsilon) _outline(wall_t);
38eca1c6d879 initial
ark
parents:
diff changeset
431 // recess over the lip, one layer higher than the lip
38eca1c6d879 initial
ark
parents:
diff changeset
432 translate([0, 0, seam_z - epsilon])
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
436 }
38eca1c6d879 initial
ark
parents:
diff changeset
437 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
458 module _hook() {
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
518 }
38eca1c6d879 initial
ark
parents:
diff changeset
519 }
38eca1c6d879 initial
ark
parents:
diff changeset
520
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
524 _latch_pin();
38eca1c6d879 initial
ark
parents:
diff changeset
525 }
38eca1c6d879 initial
ark
parents:
diff changeset
526 }
38eca1c6d879 initial
ark
parents:
diff changeset
527
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
528 // content block centred in each cell
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
529 module _content() {
0
38eca1c6d879 initial
ark
parents:
diff changeset
530 color("white", .6)
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
531 for (i = [0:1:rows - 1], j = [0:1:columns - 1])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
532 translate([_cell_x(i) - cont_x/2, _cell_y(j) - cont_y/2, floor_t])
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
533 cube([cont_x, cont_y, cont_z]);
0
38eca1c6d879 initial
ark
parents:
diff changeset
534 }
38eca1c6d879 initial
ark
parents:
diff changeset
535
38eca1c6d879 initial
ark
parents:
diff changeset
536 // filament of length l along y at x, z
38eca1c6d879 initial
ark
parents:
diff changeset
537 module _filament(x, z, l) {
38eca1c6d879 initial
ark
parents:
diff changeset
538 color("dimgray") translate([x, 0, z]) rotate([90, 0, 0])
38eca1c6d879 initial
ark
parents:
diff changeset
539 cylinder(d=filament_diameter, h=l, center=true);
38eca1c6d879 initial
ark
parents:
diff changeset
540 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
548 color("steelblue") body();
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
554 translate([-hinge_x, 0, -seam_z]) {
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
561 }
6
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
562 if (preview_content && $preview) _content();
0
38eca1c6d879 initial
ark
parents:
diff changeset
563 }
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
575 }
38eca1c6d879 initial
ark
parents:
diff changeset
576 else
38eca1c6d879 initial
ark
parents:
diff changeset
577 children();
38eca1c6d879 initial
ark
parents:
diff changeset
578 }
38eca1c6d879 initial
ark
parents:
diff changeset
579
38eca1c6d879 initial
ark
parents:
diff changeset
580 module main() {
38eca1c6d879 initial
ark
parents:
diff changeset
581 if (part == "all")
38eca1c6d879 initial
ark
parents:
diff changeset
582 part_view() _assembly();
38eca1c6d879 initial
ark
parents:
diff changeset
583 else if (part == "body")
38eca1c6d879 initial
ark
parents:
diff changeset
584 part_view() body();
38eca1c6d879 initial
ark
parents:
diff changeset
585 else if (part == "lid")
38eca1c6d879 initial
ark
parents:
diff changeset
586 part_view()
38eca1c6d879 initial
ark
parents:
diff changeset
587 if ($preview) lid();
38eca1c6d879 initial
ark
parents:
diff changeset
588 else translate([0, 0, top_z]) rotate([180, 0, 0]) lid();
38eca1c6d879 initial
ark
parents:
diff changeset
589 else if (part == "latch")
38eca1c6d879 initial
ark
parents:
diff changeset
590 part_view()
38eca1c6d879 initial
ark
parents:
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
599 }
38eca1c6d879 initial
ark
parents:
diff changeset
600
38eca1c6d879 initial
ark
parents:
diff changeset
601 main();
38eca1c6d879 initial
ark
parents:
diff changeset
602
38eca1c6d879 initial
ark
parents:
diff changeset
603 function paramstring(prefix="", suffix="") = str(
38eca1c6d879 initial
ark
parents:
diff changeset
604 prefix,
38eca1c6d879 initial
ark
parents:
diff changeset
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
f2694e49cec1 added subdivisions; lid hinge overlap fix
ark
parents: 5
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
612 "w", inner_width, "d", inner_depth, "h", inner_height,
2
e8b0aed6e3d8 adjusted lid hinge knuckles to maximise body ratio
ark
parents: 1
diff changeset
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
38eca1c6d879 initial
ark
parents:
diff changeset
616 "_lw", round(100*line_width), "lh", round(100*layer_height),
38eca1c6d879 initial
ark
parents:
diff changeset
617 suffix);
38eca1c6d879 initial
ark
parents:
diff changeset
618
38eca1c6d879 initial
ark
parents:
diff changeset
619 echo(paramstring("hinged_box_"));