comparison main.scad @ 0:b5a96b547b01

initial public version
author ark
date 2026-11-03 01:29 +0100
parents
children fe29ace8155e
comparison
equal deleted inserted replaced
-1:000000000000 0:b5a96b547b01
1 // House number: glyphs of a text, printed face down, screwed to a wall
2 // with distance washers. Glyph outlines and hole positions come from
3 // glyphs.scad, written by make_glyphs.py.
4
5 /* [part selection] */
6 // part to show or export; the decal needs two-colour mode; the template is
7 // 2D, for SVG export and make_template.py
8 part = "all"; // [all, body, decal, washer, template]
9
10 /* [layout] */
11 // whole text in one print, or one glyph per print
12 layout = "glyph"; // [text, glyph]
13 // glyph to print in the glyph layout, counted from 0, spaces not counted
14 glyph_index = 0; // [0:1:30]
15 // height of the tallest glyph, 0 for the largest that fits
16 size = 0; // [0:.1:500]
17 // rotation on the bed in degrees, -1 for the best angle
18 angle = 0; // [-1:1:90]
19 // bed size
20 bed_size = 300; // [100:1:500]
21 // unusable margin along the bed edges
22 bed_margin = 10; // [0:.5:50]
23
24 /* [glyph] */
25 // glyph thickness in layers, decal layers included
26 glyph_layers = 6; // [3:1:60]
27 // backing behind the glyph, covering its outline and connecting separate parts
28 backing = false;
29 // backing thickness in layers
30 backing_layers = 4; // [1:1:20]
31
32 /* [screws] */
33 // screw diameter
34 screw_d = 4; // [2:.5:8]
35 // countersunk holes, 90 degrees
36 countersink = true;
37 // screw head diameter
38 head_d = 8; // [3:.5:16]
39 // minimum material around the screw head, in line widths, for the fit check
40 head_wall_lines = 2; // [0:1:10]
41
42 /* [two-colour] */
43 // split into body and decal, for a filament change on a single-colour printer
44 two_colour = false;
45 // width of the decal band along the outline
46 band_width = 4; // [.5:.1:20]
47
48 /* [washer] */
49 // print the washers as part of the body, on the back of the glyph
50 washers_on_body = false;
51 // washer wall around the screw hole, in line widths
52 washer_wall_lines = 8; // [1:1:40]
53 // washer height, raised to the countersink part inside the washer plus 4 layers
54 washer_height = 10; // [0:.5:30]
55
56 /* [print settings] */
57 line_width = .4; // [0:.01:1]
58 layer_height = .2; // [0:.01:.5]
59 clearance = .1; // [0:.01:.5]
60
61 module dummy() {}
62
63 include <glyphs.scad>
64
65 epsilon = .001;
66 $fn = $preview ? 60 : 180;
67
68 lw = line_width;
69 lh = layer_height;
70
71 // thicknesses
72 glyph_t = glyph_layers * lh;
73 backing_t = backing ? backing_layers * lh : 0;
74 total_t = glyph_t + backing_t;
75 decal_t = 2 * lh; // 2 layers
76 frame_t = lh; // 1 layer
77
78 // screw holes: 90 degree countersink, depth is half the diameter difference
79 hole_d = screw_d + 2 * clearance;
80 cs_d = head_d + 2 * clearance;
81 cs_depth = countersink ? (cs_d - hole_d) / 2 : 0;
82 // part of the countersink that reaches beyond the glyph into the washer
83 cs_washer = max(0, cs_depth - total_t);
84
85 // washer
86 washer_od = hole_d + 2 * washer_wall_lines * lw;
87 washer_min = cs_washer + 4 * lh; // 4 layers below the countersink
88 washer_h = max(washer_height, washer_min);
89
90 // layout and size
91 n_glyphs = len(g_glyphs);
92 sel = layout == "text" ? [for (i = [0 : n_glyphs - 1]) i] : [glyph_index];
93 usable = bed_size - 2 * bed_margin - 4 * lw; // frame and gap, 1 line width each
94 best_angle = layout == "text" ? g_max_text[1] : g_max_glyph[1];
95 print_angle = angle < 0 ? best_angle : angle;
96 // glyphs are drawn unrotated in the assembly view
97 ang = part == "all" ? 0 : print_angle;
98 fit_extent = layout == "text"
99 ? _extent([for (g = g_glyphs) for (p = g[4]) [p.x + g[2], p.y]], print_angle)
100 : max([for (g = g_glyphs) _extent(g[4], print_angle)]);
101 max_size = usable / fit_extent * g_size;
102 final_size = size > 0 ? size : max_size;
103 k = final_size / g_size; // scale from the data file to the print
104
105 // placement: centre the bounding box of the shown glyphs on the origin
106 raw_pts = [for (i = sel) for (p = g_glyphs[i][4]) _tf0([p.x + _off(i), p.y])];
107 bb = [min([for (p = raw_pts) p.x]), min([for (p = raw_pts) p.y]),
108 max([for (p = raw_pts) p.x]), max([for (p = raw_pts) p.y])];
109 centre = [(bb[0] + bb[2]) / 2, (bb[1] + bb[3]) / 2];
110
111 // holes of the shown glyphs: [position, largest circle radius at the print size]
112 holes = [for (i = sel) for (h = g_glyphs[i][5]) [_tf([h.x + _off(i), h.y]), h[2] * k]];
113 head_r_req = head_d / 2 + head_wall_lines * lw;
114
115 assert(glyph_index < n_glyphs, str("glyph_index must be below ", n_glyphs));
116 assert(part != "decal" || two_colour, "the decal needs two_colour");
117
118 echo(str("size: ", final_size, " mm, largest that fits ", max_size, " mm at ",
119 print_angle, " degrees"));
120 echo(str("glyph thickness: ", glyph_t, " mm, with backing ", total_t, " mm"));
121 echo(str("hole: ", hole_d, " mm, countersink ", cs_d, " mm, depth ", cs_depth,
122 " mm, of which in the washer ", cs_washer, " mm"));
123 echo(str("washer: ", washer_od, " mm outside, ", washer_h, " mm high, wall ",
124 washer_wall_lines, " line widths"));
125 if (size > max_size + .01)
126 echo(str("WARNING: size ", size, " mm does not fit the bed, largest is ", max_size, " mm"));
127 if (washer_height < washer_min)
128 echo(str("WARNING: washer height raised to ", washer_min, " mm"));
129 for (h = holes) if (h[1] < head_r_req)
130 echo(str("WARNING: hole at ", h[0], ": largest circle radius ", h[1],
131 " mm, head plus wall needs ", head_r_req, " mm"));
132 if (washers_on_body) for (h = holes) if (h[1] < washer_od / 2)
133 echo(str("WARNING: washer at ", h[0], " is cut back to the glyph outline"));
134
135 // Size of the bounding box of points rotated by a degrees, along its longer side.
136 // pts: list of 2D points. a: angle in degrees.
137 function _extent(pts, a) =
138 let (r = [for (p = pts) [p.x * cos(a) - p.y * sin(a), p.x * sin(a) + p.y * cos(a)]])
139 max(max([for (q = r) q.x]) - min([for (q = r) q.x]),
140 max([for (q = r) q.y]) - min([for (q = r) q.y]));
141
142 // x offset of glyph i: its place in the text in the text layout, else 0.
143 function _off(i) = layout == "text" ? g_glyphs[i][2] : 0;
144
145 // Point from the data file to the print, before centring: scaled, rotated,
146 // mirrored for printing face down.
147 function _tf0(p) =
148 let (q = k * p, r = [q.x * cos(ang) - q.y * sin(ang), q.x * sin(ang) + q.y * cos(ang)])
149 [-r.x, r.y];
150
151 // Point from the data file to its place in the print.
152 function _tf(p) = _tf0(p) - centre;
153
154 // Apply the placement of _tf() to 2D children given in data file coordinates.
155 module _place() {
156 translate(-centre) mirror([1, 0]) rotate(ang) scale(k) children();
157 }
158
159 // Outline of glyph i in data file coordinates, at its place in the layout.
160 module _glyph2d(i) {
161 translate([_off(i), 0]) import(g_glyphs[i][1]);
162 }
163
164 // Backing outline of glyph i in data file coordinates: the outline itself,
165 // grown and shrunk to connect separate parts, or the convex hull.
166 module _backing2d(i) {
167 r = g_glyphs[i][7];
168 if (r > 0) offset(r = -r) offset(r = r) _glyph2d(i);
169 else if (r < 0) hull() _glyph2d(i);
170 else _glyph2d(i);
171 }
172
173 // Outline of all shown glyphs, placed for printing.
174 module _placed2d() {
175 for (i = sel) _place() _glyph2d(i);
176 }
177
178 // Decal band: the outline minus the outline shrunk by the band width.
179 module _band2d() {
180 difference() {
181 _placed2d();
182 offset(r = -band_width) _placed2d();
183 }
184 }
185
186 // Screw holes and countersinks, opening towards the bed, through washers
187 // printed on the body.
188 module _holes() {
189 for (h = holes) translate(h[0]) {
190 translate([0, 0, -1])
191 cylinder(d = hole_d, h = total_t + (washers_on_body ? washer_h : 0) + 2);
192 if (countersink)
193 translate([0, 0, -epsilon])
194 cylinder(d1 = cs_d + 2 * epsilon, d2 = hole_d, h = cs_depth + epsilon);
195 }
196 }
197
198 // Frame of one layer and one line width, one line width around the shown
199 // glyphs. Decal and body both contain it, so the slicer places them alike.
200 module _frame() {
201 linear_extrude(frame_t) difference() {
202 translate([bb[0] - centre.x - 2 * lw, bb[1] - centre.y - 2 * lw])
203 square([bb[2] - bb[0] + 4 * lw, bb[3] - bb[1] + 4 * lw]);
204 translate([bb[0] - centre.x - lw, bb[1] - centre.y - lw])
205 square([bb[2] - bb[0] + 2 * lw, bb[3] - bb[1] + 2 * lw]);
206 }
207 }
208
209 // Outline of the back of the shown glyphs, placed for printing: the backing
210 // if there is one, else the glyph outline.
211 module _back2d() {
212 if (backing) for (i = sel) _place() _backing2d(i);
213 else _placed2d();
214 }
215
216 // Glyph body in print orientation, face on the bed. In two-colour mode the
217 // decal band plus one line width is left out of the decal layers. Washers
218 // printed on the body stand on its back, cut back to the outline of the back
219 // so they do not overhang.
220 // frame: include the frame (two-colour mode only).
221 module body(frame = true) {
222 difference() {
223 union() {
224 linear_extrude(glyph_t) _placed2d();
225 if (backing)
226 translate([0, 0, glyph_t - epsilon]) linear_extrude(backing_t + epsilon)
227 _back2d();
228 if (washers_on_body)
229 translate([0, 0, total_t - epsilon]) intersection() {
230 for (h = holes) translate(h[0]) cylinder(d = washer_od, h = washer_h + epsilon);
231 linear_extrude(washer_h + epsilon) _back2d();
232 }
233 }
234 _holes();
235 if (two_colour)
236 translate([0, 0, -epsilon]) linear_extrude(decal_t + epsilon)
237 offset(delta = lw) _band2d();
238 }
239 if (two_colour && frame) _frame();
240 }
241
242 // Decal in print orientation: the band along the outline, with the frame.
243 // frame: include the frame.
244 module decal(frame = true) {
245 difference() {
246 linear_extrude(decal_t) _band2d();
247 _holes();
248 }
249 if (frame) _frame();
250 }
251
252 // Distance washer, printed with the glyph side up. With countersinks deeper
253 // than the glyph, the cone continues in the top of the washer.
254 module washer() {
255 difference() {
256 cylinder(d = washer_od, h = washer_h);
257 translate([0, 0, -1]) cylinder(d = hole_d, h = washer_h + 2);
258 if (cs_washer > 0)
259 translate([0, 0, washer_h - cs_washer])
260 cylinder(d1 = hole_d, d2 = hole_d + 2 * cs_washer + 2 * epsilon,
261 h = cs_washer + epsilon);
262 }
263 }
264
265 // Drilling template in 2D, as seen on the wall: all glyphs of the text at
266 // their place, a circle and cross at each hole, a level line along the
267 // baseline and a 100 mm scale bar with 10 mm ticks. Everything is made of
268 // thin strips, so the outlines of the SVG export show each line.
269 module template() {
270 t = .2; // strip width
271 // wall layout: text positions, no rotation, no mirroring
272 function pos(g, p) = k * [p.x + g[2], p.y];
273 pts = [for (g = g_glyphs) for (p = g[4]) pos(g, p)];
274 x0 = min([for (p = pts) p.x]);
275 x1 = max([for (p = pts) p.x]);
276 y0 = min([for (p = pts) p.y]);
277 arm = washer_od / 2 + 5;
278 for (g = g_glyphs) {
279 scale(k) translate([g[2], 0]) difference() {
280 import(g[1]);
281 offset(delta = -t / k) import(g[1]);
282 }
283 for (h = g[5]) translate(pos(g, h)) {
284 difference() {
285 circle(d = hole_d);
286 circle(d = hole_d - 2 * t);
287 }
288 square([2 * arm, t], center = true);
289 square([t, 2 * arm], center = true);
290 }
291 }
292 // level line along the baseline
293 translate([x0 - 20, -t / 2]) square([x1 - x0 + 40, t]);
294 // scale bar below the text
295 translate([x0, y0 - 20]) {
296 square([100, t]);
297 for (i = [0 : 10])
298 translate([10 * i - t / 2, 0]) square([t, i % 5 == 0 ? 6 : 3]);
299 }
300 }
301
302 // Assembly view: glyphs face up as on the wall, washers behind the holes.
303 module assembly() {
304 rotate([0, 180, 0]) {
305 color("lightgray") body(frame = false);
306 if (two_colour) color("firebrick") decal(frame = false);
307 if (!washers_on_body)
308 color("steelblue") for (h = holes)
309 translate([h[0].x, h[0].y, total_t + washer_h]) mirror([0, 0, 1]) washer();
310 }
311 }
312
313 // Output the selected part.
314 module main() {
315 if (part == "all") assembly();
316 else if (part == "body") body();
317 else if (part == "decal") decal();
318 else if (part == "washer") washer();
319 else if (part == "template") template();
320 }
321
322 main();
323
324 // Export file name without extension, see the print settings for lw and lh.
325 // prefix: project name with trailing underscore. suffix: appended as is.
326 function paramstring(prefix = "", suffix = "") = str(
327 prefix,
328 part == "all" ? "" : str(part, "_"),
329 part == "template" ? str(g_name, "_s", round(10 * final_size))
330 : part == "washer"
331 ? str(countersink ? "cs_" : "", "d", round(10 * screw_d), "w", washer_wall_lines,
332 "h", round(10 * washer_h), countersink ? str("c", round(10 * cs_washer)) : "")
333 : str(g_name, "_", layout == "glyph" ? str("g", glyph_index, "_") : "",
334 two_colour ? "2c_" : "", backing ? "bk_" : "", countersink ? "cs_" : "",
335 washers_on_body ? str("wh", round(10 * washer_h), "_") : "",
336 "s", round(10 * final_size), "a", round(print_angle), "t", glyph_layers),
337 "_lw", round(100 * line_width), "lh", round(100 * layer_height),
338 suffix);
339
340 echo(paramstring("house_number_"));