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