@rulecad/fixings 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +1 -1
- package/bolts.d.mts +26 -18
- package/bolts.mjs +201 -49
- package/draw.d.mts +4 -2
- package/draw.mjs +58 -17
- package/fixings.d.mts +9 -6
- package/fixings.mjs +185 -26
- package/hardware.d.mts +42 -20
- package/hardware.mjs +388 -80
- package/holes.d.mts +32 -25
- package/holes.mjs +243 -61
- package/magnets.d.mts +45 -30
- package/magnets.mjs +521 -122
- package/model.d.mts +47 -29
- package/model.mjs +751 -134
- package/package.json +16 -30
- package/pins.d.mts +46 -32
- package/pins.mjs +480 -113
- package/seats.d.mts +61 -30
- package/seats.mjs +770 -144
- package/snaps.d.mts +32 -24
- package/snaps.mjs +770 -180
- package/strength.d.mts +65 -35
- package/strength.mjs +850 -181
- package/threads.d.mts +59 -42
- package/threads.mjs +910 -193
package/magnets.mjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// together with no screw (a lid, a door's catch, a tool on a board). A magnet is a model by name (magnetModel: 'disc
|
|
3
3
|
// magnet 8x3', 'disc magnet 10x3 N52', 'block magnet 10x5x2'): its pull straight off steel from its seller's figure,
|
|
4
4
|
// scaled to its grade and across a gap, and its mass. Its pocket (magnetSeatModel) takes its fit from the printer's
|
|
5
|
-
// rules: a press, a glued fit with room for the glue, or crush ribs that take up the magnet's tolerance. The floor
|
|
6
|
-
// the pocket is held to what prints, and the pull that tries to take the magnet out of its pocket is held to what
|
|
7
|
-
// fit grips with. magnetSeat is the pocket to subtract, magnet the magnet's solid. Units: mm, N, MPa, grams.
|
|
5
|
+
// rules: a press, a glued fit with room for the glue, or crush ribs that take up the magnet's tolerance. The floor
|
|
6
|
+
// under the pocket is held to what prints, and the pull that tries to take the magnet out of its pocket is held to what
|
|
7
|
+
// the fit grips with. magnetSeat is the pocket to subtract, magnet the magnet's solid. Units: mm, N, MPa, grams.
|
|
8
8
|
import jscad from '@jscad/modeling';
|
|
9
9
|
import { crushRibs } from '@rulecad/shapes';
|
|
10
10
|
import magnetSet from '@rulecad/rules/magnets.json' with { type: 'json' };
|
|
@@ -13,19 +13,29 @@ import { along, bore, teardrop, UP, OUT } from './draw.mjs';
|
|
|
13
13
|
import { directionOf, pointOf, optionsOf, said } from './holes.mjs';
|
|
14
14
|
import { materialOf } from './strength.mjs';
|
|
15
15
|
|
|
16
|
-
const { cuboid, cylinder } = jscad.primitives,
|
|
16
|
+
const { cuboid, cylinder } = jscad.primitives,
|
|
17
|
+
{ union, subtract } = jscad.booleans,
|
|
18
|
+
{ translate } = jscad.transforms;
|
|
17
19
|
const MAGNETS = magnetSet.rules;
|
|
18
|
-
const n1 = (x) => +x.toFixed(1),
|
|
20
|
+
const n1 = (x) => +x.toFixed(1),
|
|
21
|
+
n2 = (x) => +x.toFixed(2);
|
|
19
22
|
const mrest = (k) => rest(`magnets.${k}`, MAGNETS[k]);
|
|
20
23
|
|
|
21
24
|
/** The grades of NdFeB magnet there is a remanence for, weakest first. */
|
|
22
|
-
export const MAGNET_GRADES = Object.keys(MAGNETS)
|
|
23
|
-
|
|
25
|
+
export const MAGNET_GRADES = Object.keys(MAGNETS)
|
|
26
|
+
.filter((k) => k.startsWith('remanence_'))
|
|
27
|
+
.map((k) => k.slice('remanence_'.length));
|
|
28
|
+
/** The fits a magnet takes in its pocket: press (it grips), glue (room for a film of glue), ribs (crush ribs grip
|
|
29
|
+
* it). */
|
|
24
30
|
export const MAGNET_FITS = ['press', 'glue', 'ribs'];
|
|
25
31
|
/** The sizes there is a seller's pull for: discs as diameter x thickness, blocks as length x width x thickness. */
|
|
26
32
|
export const MAGNET_SIZES = Object.freeze({
|
|
27
|
-
disc: Object.keys(MAGNETS)
|
|
28
|
-
|
|
33
|
+
disc: Object.keys(MAGNETS)
|
|
34
|
+
.filter((k) => /^disc_.*_pull$/.test(k))
|
|
35
|
+
.map((k) => k.slice(5, -5)),
|
|
36
|
+
block: Object.keys(MAGNETS)
|
|
37
|
+
.filter((k) => /^block_.*_pull$/.test(k))
|
|
38
|
+
.map((k) => k.slice(6, -5)),
|
|
29
39
|
});
|
|
30
40
|
/**
|
|
31
41
|
* The grammar a magnet's name is read by. parseMagnet reads it and nothing else does.
|
|
@@ -36,52 +46,104 @@ export const MAGNET_GRAMMAR = [
|
|
|
36
46
|
'shape = "disc magnet" | "block magnet" | "magnet" (a magnet alone is a disc; "magnets" is read too)',
|
|
37
47
|
'size = diameter "x" thickness a disc, in mm, magnetised through its thickness',
|
|
38
48
|
' | length "x" width "x" thickness a block, in mm, magnetised through its thickness',
|
|
39
|
-
'grade = "N35" | "N38" | "N40" | "N42" | "N45" | "N48" | "N50" | "N52" (default magnets.grade, N35)'
|
|
49
|
+
'grade = "N35" | "N38" | "N40" | "N42" | "N45" | "N48" | "N50" | "N52" (default magnets.grade, N35)',
|
|
40
50
|
].join('\n');
|
|
41
51
|
|
|
52
|
+
// A magnet's name: its shape, its size (two or three figures joined by x), mm if written, then the rest (its grade).
|
|
53
|
+
// Written in two pieces to keep the lines short: the pattern is the two joined.
|
|
54
|
+
const MAGNET_NAME = new RegExp(
|
|
55
|
+
/^\s*(disc\s+magnets?|block\s+magnets?|magnets?)\s+(\d*\.?\d+)\s*[x×*]\s*(\d*\.?\d+)/.source +
|
|
56
|
+
/(?:\s*[x×*]\s*(\d*\.?\d+))?\s*(?:mm\b)?\s*(.*)$/.source,
|
|
57
|
+
'i',
|
|
58
|
+
);
|
|
59
|
+
|
|
42
60
|
/**
|
|
43
61
|
* A magnet's name read by the grammar.
|
|
44
62
|
* @param {string} name 'disc magnet 8x3', 'magnet 6x2 N52', 'block magnet 10x5x2 N45'
|
|
45
|
-
* @returns {{ shape: 'disc' | 'block', diameter: number | null, length: number | null, width: number | null,
|
|
63
|
+
* @returns {{ shape: 'disc' | 'block', diameter: number | null, length: number | null, width: number | null,
|
|
64
|
+
* thickness: number, grade: string | null }}
|
|
46
65
|
*/
|
|
47
66
|
export function parseMagnet(name) {
|
|
48
|
-
const what = 'magnet name',
|
|
67
|
+
const what = 'magnet name',
|
|
68
|
+
help =
|
|
69
|
+
"A magnet is its shape, its size in mm and its grade where it has one: 'disc magnet 8x3', 'disc magnet " +
|
|
70
|
+
"10x3 N52', 'block magnet 10x5x2'";
|
|
49
71
|
if (typeof name !== 'string' || !name.trim()) throw new Error(`${what}: give a name, not ${shown(name)}. ${help}`);
|
|
50
|
-
const t =
|
|
72
|
+
const t = MAGNET_NAME.exec(name);
|
|
51
73
|
if (!t) throw new Error(`${what}: "${name}" is no magnet. ${help}`);
|
|
52
|
-
const block = /^block/i.test(t[1]),
|
|
53
|
-
|
|
74
|
+
const block = /^block/i.test(t[1]),
|
|
75
|
+
sizes = [t[2], t[3], t[4]].filter((x) => x != null).map(Number);
|
|
76
|
+
if (block !== (sizes.length === 3))
|
|
77
|
+
throw new Error(
|
|
78
|
+
`${what}: "${name}": ` +
|
|
79
|
+
(block
|
|
80
|
+
? 'a block magnet is length x width x thickness (block magnet 10x5x2)'
|
|
81
|
+
: 'a disc magnet is diameter x thickness (disc magnet 8x3); a block is named "block magnet 10x5x2"'),
|
|
82
|
+
);
|
|
54
83
|
if (!sizes.every((x) => x > 0)) throw new Error(`${what}: "${name}": a magnet's sizes are above 0 mm`);
|
|
55
|
-
const words = t[5]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
84
|
+
const words = t[5]
|
|
85
|
+
.trim()
|
|
86
|
+
.split(/[\s,]+/)
|
|
87
|
+
.filter(Boolean),
|
|
88
|
+
grade = words.length === 1 && /^n\d\d$/i.test(words[0]) ? words[0].toUpperCase() : null;
|
|
89
|
+
if (words.length && !grade)
|
|
90
|
+
throw new Error(
|
|
91
|
+
`${what}: "${name}": nothing is called "${words.join(' ')}". After the size comes only a grade: ` +
|
|
92
|
+
`${MAGNET_GRADES.join(', ')}`,
|
|
93
|
+
);
|
|
94
|
+
if (grade && !MAGNET_GRADES.includes(grade))
|
|
95
|
+
throw new Error(`${what}: "${name}": no grade ${grade}. There are: ${MAGNET_GRADES.join(', ')}`);
|
|
96
|
+
return block
|
|
97
|
+
? { shape: 'block', diameter: null, length: sizes[0], width: sizes[1], thickness: sizes[2], grade }
|
|
98
|
+
: { shape: 'disc', diameter: sizes[0], length: null, width: null, thickness: sizes[1], grade };
|
|
59
99
|
}
|
|
60
100
|
/** Whether a text is a magnet's name, by the grammar. @param {unknown} name @returns {boolean} */
|
|
61
|
-
export const isMagnetName = (name) => {
|
|
62
|
-
|
|
101
|
+
export const isMagnetName = (name) => {
|
|
102
|
+
try {
|
|
103
|
+
parseMagnet(/** @type {string} */ (name));
|
|
104
|
+
return true;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const sizeOf = (p) =>
|
|
110
|
+
p.shape === 'disc' ? `${mm(p.diameter)}x${mm(p.thickness)}` : `${mm(p.length)}x${mm(p.width)}x${mm(p.thickness)}`;
|
|
63
111
|
const magnetName = (p, grade) => `${p.shape} magnet ${sizeOf(p)} ${grade}`;
|
|
64
|
-
const middle = (g) => {
|
|
112
|
+
const middle = (g) => {
|
|
113
|
+
const [lo, hi] = MAGNETS[`remanence_${g}`].value;
|
|
114
|
+
return (lo + hi) / 2;
|
|
115
|
+
};
|
|
65
116
|
|
|
66
117
|
/**
|
|
67
118
|
* The flux density on a magnet's axis at a distance from its face, over the density at its face: the formulas of
|
|
68
119
|
* magnets.field_formula. A pull across a gap is taken as the pull touching times this squared, an estimate.
|
|
69
|
-
* @param {{ shape: 'disc' | 'block', diameter?: number | null, length?: number | null, width?: number | null,
|
|
120
|
+
* @param {{ shape: 'disc' | 'block', diameter?: number | null, length?: number | null, width?: number | null,
|
|
121
|
+
* thickness: number }} p @param {number} z mm
|
|
70
122
|
* @returns {number} B(z) / B(0)
|
|
71
123
|
*/
|
|
72
124
|
export function fieldShare(p, z) {
|
|
73
125
|
const D = p.thickness;
|
|
74
|
-
if (p.shape === 'disc') {
|
|
75
|
-
|
|
126
|
+
if (p.shape === 'disc') {
|
|
127
|
+
const R = p.diameter / 2,
|
|
128
|
+
B = (x) => (D + x) / Math.hypot(R, D + x) - (x > 0 ? x / Math.hypot(R, x) : 0);
|
|
129
|
+
return B(z) / B(0);
|
|
130
|
+
}
|
|
131
|
+
const L = p.length,
|
|
132
|
+
W = p.width,
|
|
133
|
+
B = (x) =>
|
|
134
|
+
(x > 0 ? Math.atan((L * W) / (2 * x * Math.sqrt(4 * x * x + L * L + W * W))) : Math.PI / 2) -
|
|
135
|
+
Math.atan((L * W) / (2 * (D + x) * Math.sqrt(4 * (D + x) ** 2 + L * L + W * W)));
|
|
76
136
|
return B(z) / B(0);
|
|
77
137
|
}
|
|
78
138
|
|
|
79
139
|
/**
|
|
80
|
-
* @typedef {{ kind: 'magnet', shape: 'disc' | 'block', name: string, said: string, diameter: number | null,
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
140
|
+
* @typedef {{ kind: 'magnet', shape: 'disc' | 'block', name: string, said: string, diameter: number | null,
|
|
141
|
+
* length: number | null, width: number | null, thickness: number,
|
|
142
|
+
* grade: string, made: 'bought', touching: number, gap: number, pull: number, count: number, total: number, load:
|
|
143
|
+
* number | null, margin: number | null, grams: number, volume: number, rests: object[], findings: object[] }} Magnet
|
|
144
|
+
* touching: its pull straight off thick steel it touches, N; gap: what lies between it and the steel, mm; pull:
|
|
145
|
+
* across that gap, N; count: how many share the load; total: their pull together; load and margin: the pull asked of
|
|
146
|
+
* them all, and total over it
|
|
85
147
|
*/
|
|
86
148
|
|
|
87
149
|
/**
|
|
@@ -99,54 +161,152 @@ export function fieldShare(p, z) {
|
|
|
99
161
|
export function magnetModel(p, o = {}) {
|
|
100
162
|
const what = 'magnetModel';
|
|
101
163
|
optionsOf(what, o, '{ count: 2, load: 10 }');
|
|
102
|
-
if (p && typeof p === 'object' && p.kind === 'magnet') {
|
|
164
|
+
if (p && typeof p === 'object' && p.kind === 'magnet') {
|
|
165
|
+
// a model: as it is, or built again from its name with the options given, its own figures where they say none
|
|
103
166
|
if (Object.values(o).every((x) => x === undefined)) return p;
|
|
104
167
|
const given = p.findings?.find((f) => f.code === 'magnet.pull')?.refs?.kind === 'given';
|
|
105
|
-
return magnetModel(p.name, {
|
|
168
|
+
return magnetModel(p.name, {
|
|
169
|
+
grade: o.grade ?? p.grade,
|
|
170
|
+
gap: o.gap ?? p.gap,
|
|
171
|
+
count: o.count ?? p.count,
|
|
172
|
+
load: o.load ?? p.load ?? undefined,
|
|
173
|
+
pull: o.pull ?? (given ? p.touching : undefined),
|
|
174
|
+
});
|
|
106
175
|
}
|
|
107
|
-
const n = parseMagnet(p),
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
176
|
+
const n = parseMagnet(p),
|
|
177
|
+
rests = [],
|
|
178
|
+
out = [],
|
|
179
|
+
size = sizeOf(n),
|
|
180
|
+
key = `${n.shape}_${size}`;
|
|
181
|
+
if (o.grade != null && !MAGNET_GRADES.includes(o.grade))
|
|
182
|
+
throw new Error(`${what}: grade is one of ${MAGNET_GRADES.join(', ')} (got ${shown(o.grade)})`);
|
|
183
|
+
const grade = o.grade ?? n.grade ?? MAGNETS.grade.value,
|
|
184
|
+
gap = o.gap ?? 0,
|
|
185
|
+
count = o.count ?? 1;
|
|
186
|
+
if (!(isNum(gap) && gap >= 0))
|
|
187
|
+
throw new Error(`${what}: gap is what lies between the magnet and the steel, 0 mm or more (got ${shown(o.gap)})`);
|
|
188
|
+
if (!(Number.isInteger(count) && count >= 1))
|
|
189
|
+
throw new Error(`${what}: count is how many magnets share the load, a whole number from 1 (got ${shown(o.count)})`);
|
|
112
190
|
if (o.grade == null && n.grade == null) rests.push(mrest('grade'));
|
|
113
191
|
let touching, says;
|
|
114
|
-
if (o.pull != null) {
|
|
115
|
-
|
|
192
|
+
if (o.pull != null) {
|
|
193
|
+
touching = positive(what, "pull (a magnet's pull touching steel, in N)", o.pull);
|
|
194
|
+
says = `${mm(touching)} N touching steel, as given`;
|
|
195
|
+
} else {
|
|
116
196
|
const f = MAGNETS[`${key}_pull`];
|
|
117
|
-
if (!f)
|
|
118
|
-
|
|
119
|
-
|
|
197
|
+
if (!f)
|
|
198
|
+
throw new Error(
|
|
199
|
+
`${what}: there is no seller's pull for a ${n.shape} magnet ${size}: the kit holds ` +
|
|
200
|
+
`${MAGNET_SIZES[n.shape].join(', ')} (magnets.${n.shape}_<size>_pull). For another size, give its ` +
|
|
201
|
+
`maker's pull touching steel ({ pull: 12 }, in N)`,
|
|
202
|
+
);
|
|
203
|
+
const sold = MAGNETS[`${key}_grade`].value,
|
|
204
|
+
k = (middle(grade) / middle(sold)) ** 2;
|
|
205
|
+
touching = f.value * k;
|
|
206
|
+
rests.push(mrest(`${key}_pull`), mrest(`${key}_grade`));
|
|
120
207
|
if (grade !== sold) rests.push(mrest(`remanence_${grade}`), mrest(`remanence_${sold}`));
|
|
121
|
-
says =
|
|
208
|
+
says =
|
|
209
|
+
grade === sold
|
|
210
|
+
? `${mm(f.value)} N touching steel, its seller's figure (magnets.${key}_pull, ${sold})`
|
|
211
|
+
: `${mm(n2(touching))} N touching steel: its seller's ${mm(f.value)} N for ${sold} (magnets.${key}` +
|
|
212
|
+
`_pull) times (${mm(r3(middle(grade)))} / ${mm(r3(middle(sold)))} T)² for ${grade}, the middles of ` +
|
|
213
|
+
`their remanence (magnets.remanence_${grade}, an estimate)`;
|
|
122
214
|
}
|
|
123
|
-
const share = gap > 0 ? fieldShare(n, gap) ** 2 : 1,
|
|
215
|
+
const share = gap > 0 ? fieldShare(n, gap) ** 2 : 1,
|
|
216
|
+
pull = touching * share;
|
|
124
217
|
if (gap > 0) rests.push(mrest('field_formula'));
|
|
125
|
-
const volume = n.shape === 'disc' ? (Math.PI / 4) * n.diameter ** 2 * n.thickness : n.length * n.width * n.thickness,
|
|
218
|
+
const volume = n.shape === 'disc' ? (Math.PI / 4) * n.diameter ** 2 * n.thickness : n.length * n.width * n.thickness,
|
|
219
|
+
grams = r3((volume * MAGNETS.density.value) / 1000);
|
|
126
220
|
rests.push(mrest('density'));
|
|
127
221
|
const name = magnetName(n, grade);
|
|
128
|
-
out.push(
|
|
129
|
-
|
|
130
|
-
|
|
222
|
+
out.push(
|
|
223
|
+
finding(
|
|
224
|
+
'info',
|
|
225
|
+
`${name} pulls ${says}` +
|
|
226
|
+
(gap > 0
|
|
227
|
+
? `; across a ${mm(gap)} mm gap ${mm(n2(pull))} N, ${mm(n1(share * 100))}% of that (the field on its ` +
|
|
228
|
+
`axis squared, magnets.field_formula: an estimate)`
|
|
229
|
+
: '') +
|
|
230
|
+
`. A seller's pull is straight off thick mild steel: a thin strike, a slide sideways or a rough face ` +
|
|
231
|
+
`takes less`,
|
|
232
|
+
'magnet.pull',
|
|
233
|
+
{
|
|
234
|
+
values: { touching: n2(touching), gap, pull: n2(pull), grade },
|
|
235
|
+
refs: {
|
|
236
|
+
magnet: name,
|
|
237
|
+
kind: o.pull != null ? 'given' : grade === MAGNETS[`${key}_grade`]?.value ? 'community' : 'estimate',
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
),
|
|
241
|
+
);
|
|
242
|
+
const total = pull * count,
|
|
243
|
+
load = o.load != null ? positive(what, 'load (the pull asked of the magnets, in N)', o.load) : null,
|
|
244
|
+
want = DEFAULTS.load_margin.value;
|
|
131
245
|
let margin = null;
|
|
132
246
|
if (load != null) {
|
|
133
|
-
margin = n2(total / load);
|
|
134
|
-
|
|
247
|
+
margin = n2(total / load);
|
|
248
|
+
rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
|
|
249
|
+
out.push(
|
|
250
|
+
finding(
|
|
251
|
+
margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail',
|
|
252
|
+
(count > 1 ? `${count} × ${name} pull ${mm(n2(total))} N together` : `${name} pulls ${mm(n2(pull))} N`) +
|
|
253
|
+
`: a pull of ${mm(load)} N is held ${mm(margin)} times over` +
|
|
254
|
+
(margin >= want
|
|
255
|
+
? ''
|
|
256
|
+
: margin >= 1
|
|
257
|
+
? `, under the ${mm(want)} times fixings.load_margin asks`
|
|
258
|
+
: ': it comes apart'),
|
|
259
|
+
'magnet.hold',
|
|
260
|
+
{ values: { total: n2(total), load, margin, count } },
|
|
261
|
+
),
|
|
262
|
+
);
|
|
135
263
|
}
|
|
136
|
-
out.push(
|
|
137
|
-
|
|
138
|
-
|
|
264
|
+
out.push(
|
|
265
|
+
finding(
|
|
266
|
+
'info',
|
|
267
|
+
`${name} weighs ${mm(grams)} g (magnets.density ${mm(MAGNETS.density.value)} g/cm³)`,
|
|
268
|
+
'magnet.mass',
|
|
269
|
+
{ values: { grams } },
|
|
270
|
+
),
|
|
271
|
+
);
|
|
272
|
+
return {
|
|
273
|
+
kind: 'magnet',
|
|
274
|
+
shape: n.shape,
|
|
275
|
+
name,
|
|
276
|
+
said: String(p),
|
|
277
|
+
diameter: n.diameter,
|
|
278
|
+
length: n.length,
|
|
279
|
+
width: n.width,
|
|
280
|
+
thickness: n.thickness,
|
|
281
|
+
grade,
|
|
282
|
+
made: 'bought',
|
|
283
|
+
touching: n2(touching),
|
|
284
|
+
gap,
|
|
285
|
+
pull: n2(pull),
|
|
286
|
+
count,
|
|
287
|
+
total: n2(total),
|
|
288
|
+
load,
|
|
289
|
+
margin,
|
|
290
|
+
grams,
|
|
291
|
+
volume: n2(volume),
|
|
292
|
+
rests,
|
|
293
|
+
findings: out,
|
|
294
|
+
};
|
|
139
295
|
}
|
|
140
296
|
|
|
141
297
|
/**
|
|
142
298
|
* @typedef {{ kind: 'magnet-seat', magnet: Magnet, fit: 'press' | 'glue' | 'ribs', facing: 'open' | 'floor',
|
|
143
|
-
* pocket: { shape: 'round' | 'rect', diameter: number | null, size: number[] | null, nominal: number[], comp: number,
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
299
|
+
* pocket: { shape: 'round' | 'rect', diameter: number | null, size: number[] | null, nominal: number[], comp: number,
|
|
300
|
+
* clearance: number, depth: number, lead: number,
|
|
301
|
+
* into: string, axis: 'x' | 'y' | 'z', teardrop: boolean, ribs:
|
|
302
|
+
* { count: number, tips: number, radius: number, protrude: number } | null, relief: number | null, rules: string[]
|
|
303
|
+
* },
|
|
304
|
+
* floor: number | null, thickness: number | null, hold: number | null, holdMargin: number | null, rests: object[],
|
|
305
|
+
* findings: object[] }} MagnetSeat pocket: what to draw (diameter of a round pocket, or [length, width] of a block's,
|
|
306
|
+
* as drawn; nominal: the magnet's; comp: hole compensation added; clearance: added across past that, under 0 for a
|
|
307
|
+
* press; lead: the chamfer at its mouth; ribs: crush ribs, their tips on a circle `tips` across; relief: a block
|
|
308
|
+
* pocket's corner reliefs' radius); floor: what is left under it in a part `thickness` thick; hold: what the fit
|
|
309
|
+
* grips the magnet with against its pull out, N
|
|
150
310
|
*/
|
|
151
311
|
|
|
152
312
|
/**
|
|
@@ -157,123 +317,362 @@ export function magnetModel(p, o = {}) {
|
|
|
157
317
|
* would not print: a pocket opening on the bed wider than the printer bridges, a block's pocket or crush ribs lying on
|
|
158
318
|
* their side, a floor too thin.
|
|
159
319
|
* @param {string | Magnet} p a magnet's name or model
|
|
160
|
-
* @param {{ fit?: 'press' | 'glue' | 'ribs', printer?: object, material?: string | object, sets?: object,
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
* the
|
|
166
|
-
*
|
|
320
|
+
* @param {{ fit?: 'press' | 'glue' | 'ribs', printer?: object, material?: string | object, sets?: object,
|
|
321
|
+
* into?: string, axis?: 'x' | 'y' | 'z',
|
|
322
|
+
* recess?: number, thickness?: number, facing?: 'open' | 'floor', grade?: string, gap?: number, count?: number,
|
|
323
|
+
* load?: number, pull?: number }} [o] fit: press, glue or ribs (the default: ribs for a disc standing in its pocket;
|
|
324
|
+
* glue for a disc lying on its side, where ribs would hang from the roof, and for a block, whose press splits its
|
|
325
|
+
* wall); material: the part's plastic (default PLA); into or axis: the pocket's way (default down from a top face);
|
|
326
|
+
* recess: how far under the face the magnet sits, mm; thickness: the part's along the pocket, for its floor; facing:
|
|
327
|
+
* where the magnet's steel is, past the pocket's open face (the default) or through its floor, which is then the gap;
|
|
328
|
+
* grade, gap, count, load, pull: magnetModel's
|
|
167
329
|
* @returns {MagnetSeat}
|
|
168
330
|
*/
|
|
169
331
|
export function magnetSeatModel(p, o = {}) {
|
|
170
332
|
const what = 'magnetSeatModel';
|
|
171
|
-
optionsOf(what, o,
|
|
172
|
-
const pr = printerOf(what, o.printer),
|
|
173
|
-
|
|
333
|
+
optionsOf(what, o, "{ fit: 'press', thickness: 5 }");
|
|
334
|
+
const pr = printerOf(what, o.printer),
|
|
335
|
+
dir = directionOf(what, o, '-z'),
|
|
336
|
+
out = [],
|
|
337
|
+
rests = [];
|
|
338
|
+
const model = typeof p === 'object' && p?.kind === 'magnet',
|
|
339
|
+
n = model ? p : parseMagnet(p);
|
|
174
340
|
// The fit by default: crush ribs for a disc standing in its pocket, glue for one lying on its side (ribs would hang
|
|
175
341
|
// from its roof) and for a block. A press grips well, but its hoop stress splits a thin wall: an 8x3 disc in PLA at
|
|
176
342
|
// x1c.magnet_press is stretched 24.6 MPa round its hoop against 39 / 2, a 10x5x2 block 39.4 MPa against 39
|
|
177
|
-
const fit = oneOf(what, 'fit', o.fit ?? (n.shape === 'disc' && !dir.across ? 'ribs' : 'glue'), MAGNET_FITS),
|
|
343
|
+
const fit = oneOf(what, 'fit', o.fit ?? (n.shape === 'disc' && !dir.across ? 'ribs' : 'glue'), MAGNET_FITS),
|
|
344
|
+
facing = oneOf(what, 'facing', o.facing ?? 'open', ['open', 'floor']);
|
|
178
345
|
const recess = o.recess ?? 0;
|
|
179
|
-
if (!(isNum(recess) && recess >= 0))
|
|
346
|
+
if (!(isNum(recess) && recess >= 0))
|
|
347
|
+
throw new Error(`${what}: recess is how far under the face the magnet sits, 0 mm or more (got ${shown(o.recess)})`);
|
|
180
348
|
const mat = materialOf(what, o.material ?? 'pla', o.sets);
|
|
181
|
-
const layer = pr.n('layer'),
|
|
349
|
+
const layer = pr.n('layer'),
|
|
350
|
+
least = r3(DEFAULTS.magnet_floor.value * layer),
|
|
351
|
+
depth = r3(n.thickness + recess);
|
|
182
352
|
// The floor: what the part leaves under the pocket, and (facing the floor) the gap the pull goes across
|
|
183
|
-
let floor = null,
|
|
353
|
+
let floor = null,
|
|
354
|
+
thickness = null;
|
|
184
355
|
if (o.thickness != null) {
|
|
185
|
-
thickness = positive(what, 'thickness', o.thickness);
|
|
186
|
-
|
|
356
|
+
thickness = positive(what, 'thickness', o.thickness);
|
|
357
|
+
floor = r3(thickness - depth);
|
|
358
|
+
if (floor < least - 1e-9)
|
|
359
|
+
throw new Error(
|
|
360
|
+
`${what}: a pocket ${mm(depth)} mm deep in a part ${mm(thickness)} mm thick there leaves a floor of ` +
|
|
361
|
+
`${mm(floor)} mm under the magnet, under fixings.magnet_floor's ${DEFAULTS.magnet_floor.value} ` +
|
|
362
|
+
`layers (${mm(least)} mm at ${pr.cite('layer')} ${mm(layer)} mm): too thin to print whole, and the ` +
|
|
363
|
+
`magnet pulls through it. Make the part ${mm(r3(depth + least))} mm thick there, or the pocket ` +
|
|
364
|
+
`shallower`,
|
|
365
|
+
);
|
|
187
366
|
rests.push(rest('fixings.magnet_floor', DEFAULTS.magnet_floor), pr.rest('layer'));
|
|
188
|
-
} else if (facing === 'floor')
|
|
367
|
+
} else if (facing === 'floor')
|
|
368
|
+
throw new Error(
|
|
369
|
+
`${what}: facing 'floor' pulls through the floor under the pocket: give thickness, the part's along ` +
|
|
370
|
+
`the pocket, so the floor is known`,
|
|
371
|
+
);
|
|
189
372
|
// (a model handed in is built again with these options, so its pull is taken across this floor and held to this load)
|
|
190
|
-
const m = magnetModel(p, {
|
|
191
|
-
|
|
373
|
+
const m = magnetModel(p, {
|
|
374
|
+
grade: o.grade,
|
|
375
|
+
gap: (facing === 'floor' ? floor : 0) + (o.gap ?? (model ? p.gap : 0)),
|
|
376
|
+
count: o.count,
|
|
377
|
+
load: o.load,
|
|
378
|
+
pull: o.pull,
|
|
379
|
+
});
|
|
380
|
+
rests.push(...m.rests);
|
|
381
|
+
out.push(...m.findings);
|
|
192
382
|
// The pocket: the magnet, plus hole_comp as any printed hole, less magnet_press or plus magnet_glue
|
|
193
|
-
const comp = pr.n('hole_comp'),
|
|
383
|
+
const comp = pr.n('hole_comp'),
|
|
384
|
+
k = fit === 'press' ? 'magnet_press' : 'magnet_glue',
|
|
385
|
+
c = pr.n(k),
|
|
386
|
+
clearance = r3(fit === 'press' ? -c : c);
|
|
194
387
|
rests.push(pr.rest('hole_comp'), pr.rest(k));
|
|
195
|
-
const disc = m.shape === 'disc',
|
|
196
|
-
|
|
388
|
+
const disc = m.shape === 'disc',
|
|
389
|
+
nominal = disc ? [m.diameter] : [m.length, m.width],
|
|
390
|
+
drawn = nominal.map((x) => r3(x + comp + clearance)),
|
|
391
|
+
rules = [pr.cite('hole_comp'), pr.cite(k)];
|
|
392
|
+
let ribs = null,
|
|
393
|
+
relief = null;
|
|
197
394
|
if (fit === 'ribs') {
|
|
198
|
-
if (!disc)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
395
|
+
if (!disc)
|
|
396
|
+
throw new Error(`${what}: crush ribs are for a round pocket: a block magnet's pocket is pressed or glued`);
|
|
397
|
+
if (dir.across)
|
|
398
|
+
throw new Error(
|
|
399
|
+
`${what}: crush ribs lying on their side (${said(dir.into)}) hang from the pocket's roof: stand the ` +
|
|
400
|
+
`pocket up, or press or glue the magnet`,
|
|
401
|
+
);
|
|
402
|
+
const crush = pr.n('magnet_crush'),
|
|
403
|
+
tips = r3(m.diameter + comp - crush),
|
|
404
|
+
line = pr.n('line'),
|
|
405
|
+
protrude = r3((drawn[0] - tips) / 2);
|
|
406
|
+
ribs = { count: 3, tips, radius: r3(Math.max(line / 2, protrude)), protrude };
|
|
407
|
+
rules.push(pr.cite('magnet_crush'));
|
|
408
|
+
rests.push(pr.rest('magnet_crush'), pr.rest('line'));
|
|
202
409
|
}
|
|
203
410
|
if (!disc) {
|
|
204
|
-
if (dir.across)
|
|
205
|
-
|
|
411
|
+
if (dir.across)
|
|
412
|
+
throw new Error(
|
|
413
|
+
`${what}: a block magnet's pocket lying on its side (${said(dir.into)}) has a flat roof hanging over ` +
|
|
414
|
+
`it: stand the pocket up (into -z, down from a top face)`,
|
|
415
|
+
);
|
|
416
|
+
relief = r3(pr.n('line'));
|
|
417
|
+
rests.push(pr.rest('line'));
|
|
206
418
|
}
|
|
207
419
|
if (dir.into === '+z') {
|
|
208
|
-
const span = disc ? drawn[0] : Math.min(...drawn),
|
|
209
|
-
|
|
420
|
+
const span = disc ? drawn[0] : Math.min(...drawn),
|
|
421
|
+
bridge = pr.n('bridge');
|
|
422
|
+
if (span > bridge + 1e-9)
|
|
423
|
+
throw new Error(
|
|
424
|
+
`${what}: a pocket going up from the bed ${mm(span)} mm across has its floor printed over it as a ` +
|
|
425
|
+
`bridge, wider than ${pr.cite('bridge')} ${mm(bridge)} mm: print the part with the pocket opening ` +
|
|
426
|
+
`upward (into -z)`,
|
|
427
|
+
);
|
|
210
428
|
rests.push(pr.rest('bridge'));
|
|
211
429
|
}
|
|
212
430
|
const lead = fit === 'glue' || dir.across || !disc ? 0 : r3(Math.min(pr.n('chamfer'), depth / 3));
|
|
213
431
|
if (lead) rests.push(pr.rest('chamfer'));
|
|
214
|
-
const pocket = {
|
|
432
|
+
const pocket = {
|
|
433
|
+
shape: disc ? 'round' : 'rect',
|
|
434
|
+
diameter: disc ? drawn[0] : null,
|
|
435
|
+
size: disc ? null : drawn,
|
|
436
|
+
nominal,
|
|
437
|
+
comp,
|
|
438
|
+
clearance,
|
|
439
|
+
depth,
|
|
440
|
+
lead,
|
|
441
|
+
into: dir.into,
|
|
442
|
+
axis: dir.axis,
|
|
443
|
+
teardrop: disc && dir.across,
|
|
444
|
+
ribs,
|
|
445
|
+
relief,
|
|
446
|
+
rules,
|
|
447
|
+
};
|
|
215
448
|
const across = disc ? `${mm(drawn[0])} mm across` : `${mm(drawn[0])} x ${mm(drawn[1])} mm`;
|
|
216
|
-
out.push(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
449
|
+
out.push(
|
|
450
|
+
finding(
|
|
451
|
+
'info',
|
|
452
|
+
`${m.name}'s ${fit === 'ribs' ? 'ribbed' : fit} pocket drawn ${across}, ${mm(depth)} mm deep` +
|
|
453
|
+
(recess ? ` (the magnet ${mm(recess)} mm under the face)` : '') +
|
|
454
|
+
`: the magnet's ${nominal.map(mm).join(' x ')} mm, plus ${pr.cite('hole_comp')} ${mm(comp)} mm since a ` +
|
|
455
|
+
`printed hole comes out small, ${fit === 'press' ? 'less' : 'plus'} ${pr.cite(k)} ${mm(c)} mm (` +
|
|
456
|
+
`${pr.rest(k).kind})` +
|
|
457
|
+
(ribs
|
|
458
|
+
? `, with ${ribs.count} crush ribs whose tips stand ${mm(ribs.tips)} mm across (` +
|
|
459
|
+
`${pr.cite('magnet_crush')} ${mm(pr.n('magnet_crush'))} mm inside the magnet and hole_comp)`
|
|
460
|
+
: '') +
|
|
461
|
+
(relief
|
|
462
|
+
? `, its corners relieved by ${mm(relief)} mm round cuts so the block's square corners go in and no ` +
|
|
463
|
+
`inside corner is square`
|
|
464
|
+
: '') +
|
|
465
|
+
(lead ? `, a ${mm(lead)} mm lead-in at its mouth` : ''),
|
|
466
|
+
'magnet.pocket',
|
|
467
|
+
{
|
|
468
|
+
values: { diameter: pocket.diameter, size: pocket.size, depth, clearance },
|
|
469
|
+
refs: { magnet: m.name, fit, rule: pr.cite(k), kind: pr.rest(k).kind },
|
|
470
|
+
},
|
|
471
|
+
),
|
|
472
|
+
);
|
|
473
|
+
if (fit === 'press')
|
|
474
|
+
out.push(
|
|
475
|
+
finding(
|
|
476
|
+
'info',
|
|
477
|
+
`a magnet is sold within ±${mm(MAGNETS.tolerance.value)} mm (magnets.tolerance), as much as the ` +
|
|
478
|
+
`${mm(c)} mm press: a small one may drop in loose and a large one split the pocket. Crush ribs (fit ` +
|
|
479
|
+
`'ribs') take up the spread`,
|
|
480
|
+
'magnet.tolerance',
|
|
481
|
+
{ values: { tolerance: MAGNETS.tolerance.value, press: c } },
|
|
482
|
+
),
|
|
483
|
+
);
|
|
484
|
+
out.push(
|
|
485
|
+
finding(
|
|
486
|
+
'pass',
|
|
487
|
+
`${said(dir.into)}, the pocket ` +
|
|
488
|
+
(dir.across
|
|
489
|
+
? 'is a teardrop: a 45° roof, so it prints with no support'
|
|
490
|
+
: dir.into === '+z'
|
|
491
|
+
? `opens on the bed, its floor a ${mm(disc ? drawn[0] : Math.min(...drawn))} mm bridge`
|
|
492
|
+
: 'opens upward, so it prints as drawn') +
|
|
493
|
+
(floor != null
|
|
494
|
+
? `; it leaves a ${mm(floor)} mm floor, ${DEFAULTS.magnet_floor.value} layers or more ` +
|
|
495
|
+
`(fixings.magnet_floor)`
|
|
496
|
+
: ''),
|
|
497
|
+
'magnet.printable',
|
|
498
|
+
{ values: { into: dir.into, floor } },
|
|
499
|
+
),
|
|
500
|
+
);
|
|
220
501
|
// The pull out of the pocket: facing the open face, the magnet's own pull on its steel draws it out against the fit
|
|
221
|
-
let hold = null,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
502
|
+
let hold = null,
|
|
503
|
+
holdMargin = null;
|
|
504
|
+
const want = DEFAULTS.load_margin.value,
|
|
505
|
+
mu = DEFAULTS.clamp_friction.value,
|
|
506
|
+
wall = disc ? Math.PI * m.diameter * m.thickness : 2 * (m.length + m.width) * m.thickness;
|
|
507
|
+
if (facing === 'floor')
|
|
508
|
+
out.push(
|
|
509
|
+
finding(
|
|
510
|
+
'pass',
|
|
511
|
+
`the steel is past the floor, so the magnet's pull holds it down in its pocket: it cannot pull out ` +
|
|
512
|
+
`(the ${mm(floor)} mm floor is its gap)`,
|
|
513
|
+
'magnet.pullout',
|
|
514
|
+
{ values: { floor } },
|
|
515
|
+
),
|
|
516
|
+
);
|
|
517
|
+
else if (fit === 'glue')
|
|
518
|
+
out.push(
|
|
519
|
+
finding(
|
|
520
|
+
'info',
|
|
521
|
+
`glued, the magnet stays in its pocket by its glue, whose strength is its maker's and not checked ` +
|
|
522
|
+
`here: it is pulled out with ${mm(m.pull)} N, so the glue must hold ${mm(n1(want * m.pull))} N ` +
|
|
523
|
+
`(fixings.load_margin times the pull) over ${mm(n1(wall))} mm² of wall`,
|
|
524
|
+
'magnet.pullout',
|
|
525
|
+
{ values: { pull: m.pull, area: n1(wall) } },
|
|
526
|
+
),
|
|
527
|
+
);
|
|
225
528
|
else {
|
|
226
529
|
let says;
|
|
227
|
-
if (fit === 'press') {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
530
|
+
if (fit === 'press') {
|
|
531
|
+
// a rigid magnet in a hole in a wide plate: p = E (i / d) / (1 + ν), held by friction over its wall
|
|
532
|
+
const E = mat.modulus.value,
|
|
533
|
+
nu = mat.poisson?.value ?? 0.35,
|
|
534
|
+
p0 = (E * (c / (disc ? m.diameter : Math.min(m.length, m.width)))) / (1 + nu);
|
|
535
|
+
hold = n1(mu * p0 * wall);
|
|
536
|
+
rests.push(
|
|
537
|
+
rest(mat.modulus.name, mat.modulus),
|
|
538
|
+
...(mat.poisson ? [rest(mat.poisson.name, mat.poisson)] : []),
|
|
539
|
+
rest('fixings.clamp_friction', DEFAULTS.clamp_friction),
|
|
540
|
+
);
|
|
541
|
+
says =
|
|
542
|
+
`a ${mm(c)} mm press in ${mat.name} grips at about ${mm(n2(p0))} MPa (p = E i / d / (1 + ν), ` +
|
|
543
|
+
`${mat.modulus.name} ${mm(E)} MPa, ν ${mm(nu)}` +
|
|
544
|
+
(mat.poisson ? '' : ', taken for a plastic with none in its rule set') +
|
|
545
|
+
`), ${mm(hold)} N over its ${mm(n1(wall))} mm² wall at fixings.clamp_friction ${mm(mu)}: an estimate, ` +
|
|
546
|
+
`which a plastic loses some of as it creeps`;
|
|
547
|
+
} else {
|
|
548
|
+
// crush ribs crushed: each presses at the plastic's strength over a line's width
|
|
549
|
+
const S = mat.strength.value,
|
|
550
|
+
w = pr.n('line'),
|
|
551
|
+
area = ribs.count * w * m.thickness;
|
|
552
|
+
hold = n1(mu * S * area);
|
|
553
|
+
rests.push(rest(mat.strength.name, mat.strength), rest('fixings.clamp_friction', DEFAULTS.clamp_friction));
|
|
554
|
+
says =
|
|
555
|
+
`${ribs.count} crush ribs, crushed, press at ${mat.name}'s ${mm(S)} MPa over ${mm(n2(area))} mm² (a ` +
|
|
556
|
+
`${mm(w)} mm line by the magnet's ${mm(m.thickness)} mm each), ${mm(hold)} N at fixings.clamp_friction ` +
|
|
557
|
+
`${mm(mu)}: an estimate`;
|
|
235
558
|
}
|
|
236
|
-
if (fit === 'press') {
|
|
237
|
-
|
|
238
|
-
|
|
559
|
+
if (fit === 'press') {
|
|
560
|
+
// the pocket's wall, round a rigid magnet in a wide plate, is stretched round its hoop by the same pressure
|
|
561
|
+
const p0 =
|
|
562
|
+
(mat.modulus.value * (c / (disc ? m.diameter : Math.min(m.length, m.width)))) /
|
|
563
|
+
(1 + (mat.poisson?.value ?? 0.35)),
|
|
564
|
+
S = mat.strength.value;
|
|
565
|
+
out.push(
|
|
566
|
+
finding(
|
|
567
|
+
p0 <= S / want + 1e-9 ? 'pass' : p0 <= S + 1e-9 ? 'warn' : 'fail',
|
|
568
|
+
`the press stretches the pocket's wall round its hoop at about ${mm(n2(p0))} MPa, against ` +
|
|
569
|
+
`${mat.strength.name} ${mm(S)} MPa` +
|
|
570
|
+
(p0 <= S / want + 1e-9
|
|
571
|
+
? ''
|
|
572
|
+
: p0 <= S
|
|
573
|
+
? `: under ${mm(want)} times over, so a magnet at the top of its tolerance may split a thin wall. ` +
|
|
574
|
+
`Crush ribs (fit 'ribs') press far less`
|
|
575
|
+
: ": it splits the wall. Use crush ribs (fit 'ribs') or glue"),
|
|
576
|
+
'magnet.wall',
|
|
577
|
+
{ values: { hoop: n2(p0), strength: S } },
|
|
578
|
+
),
|
|
579
|
+
);
|
|
239
580
|
}
|
|
240
581
|
holdMargin = n2(hold / m.pull);
|
|
241
|
-
out.push(
|
|
242
|
-
|
|
582
|
+
out.push(
|
|
583
|
+
finding(
|
|
584
|
+
holdMargin >= want ? 'pass' : holdMargin >= 1 ? 'warn' : 'fail',
|
|
585
|
+
`the magnet is pulled out of its pocket with its own ${mm(m.pull)} N: ${says}, ${mm(holdMargin)} ` +
|
|
586
|
+
`times the pull` +
|
|
587
|
+
(holdMargin >= want
|
|
588
|
+
? ''
|
|
589
|
+
: holdMargin >= 1
|
|
590
|
+
? `, under the ${mm(want)} times fixings.load_margin asks: glue it as well`
|
|
591
|
+
: ': it comes out, so glue it'),
|
|
592
|
+
'magnet.pullout',
|
|
593
|
+
{ values: { hold, pull: m.pull, margin: holdMargin } },
|
|
594
|
+
),
|
|
595
|
+
);
|
|
243
596
|
}
|
|
244
|
-
return {
|
|
597
|
+
return {
|
|
598
|
+
kind: 'magnet-seat',
|
|
599
|
+
magnet: m,
|
|
600
|
+
fit,
|
|
601
|
+
facing,
|
|
602
|
+
pocket,
|
|
603
|
+
floor,
|
|
604
|
+
thickness,
|
|
605
|
+
hold,
|
|
606
|
+
holdMargin,
|
|
607
|
+
rests,
|
|
608
|
+
findings: out,
|
|
609
|
+
};
|
|
245
610
|
}
|
|
246
611
|
|
|
247
612
|
/**
|
|
248
613
|
* A magnet's pocket, to subtract: round (a teardrop lying on its side) with crush ribs where asked, or a block's with
|
|
249
614
|
* its corners relieved, the size magnetSeatModel gives it, from the point at on the face going into the part.
|
|
250
|
-
* @param {string | Magnet} p @param {object} [o] as magnetSeatModel, and at: the point on the face where the pocket
|
|
615
|
+
* @param {string | Magnet} p @param {object} [o] as magnetSeatModel, and at: the point on the face where the pocket
|
|
616
|
+
* starts
|
|
251
617
|
* @returns {object} a JSCAD geom3 with .model holding magnetSeatModel's numbers
|
|
252
618
|
*/
|
|
253
619
|
export function magnetSeat(p, o = {}) {
|
|
254
|
-
const what = 'magnetSeat',
|
|
620
|
+
const what = 'magnetSeat',
|
|
621
|
+
s = magnetSeatModel(p, optionsOf(what, o, "{ fit: 'ribs', at: [0, 0, 5] }")),
|
|
622
|
+
at = pointOf(what, o.at),
|
|
623
|
+
q = s.pocket;
|
|
255
624
|
let g;
|
|
256
625
|
if (q.shape === 'round') {
|
|
257
|
-
const r = q.diameter / 2,
|
|
626
|
+
const r = q.diameter / 2,
|
|
627
|
+
steps = q.lead
|
|
628
|
+
? [
|
|
629
|
+
[r + q.lead, 0],
|
|
630
|
+
[r, q.lead],
|
|
631
|
+
[r, q.depth],
|
|
632
|
+
]
|
|
633
|
+
: [[r, q.depth]];
|
|
258
634
|
g = q.teardrop ? teardrop(steps, UP[q.into]) : bore(steps);
|
|
259
635
|
if (q.ribs) {
|
|
260
|
-
const { count, radius, protrude } = q.ribs,
|
|
261
|
-
|
|
636
|
+
const { count, radius, protrude } = q.ribs,
|
|
637
|
+
a = Array.from({ length: count }, (_, i) => (2 * Math.PI * i) / count + Math.PI / 2);
|
|
638
|
+
g = subtract(
|
|
639
|
+
g,
|
|
640
|
+
crushRibs({
|
|
641
|
+
at: a.map((t) => [r * Math.cos(t), r * Math.sin(t)]),
|
|
642
|
+
into: a.map((t) => [-Math.cos(t), -Math.sin(t)]),
|
|
643
|
+
z: [-q.depth - OUT, q.lead ? -q.lead : OUT],
|
|
644
|
+
radius,
|
|
645
|
+
protrude,
|
|
646
|
+
}),
|
|
647
|
+
);
|
|
262
648
|
}
|
|
263
649
|
} else {
|
|
264
|
-
const [L, W] = q.size,
|
|
265
|
-
|
|
650
|
+
const [L, W] = q.size,
|
|
651
|
+
h = q.depth + OUT,
|
|
652
|
+
box = translate([0, 0, OUT - h / 2], cuboid({ size: [L, W, h] }));
|
|
653
|
+
const corners = [
|
|
654
|
+
[1, 1],
|
|
655
|
+
[-1, 1],
|
|
656
|
+
[-1, -1],
|
|
657
|
+
[1, -1],
|
|
658
|
+
].map(([sx, sy]) =>
|
|
659
|
+
translate([(sx * L) / 2, (sy * W) / 2, OUT - h / 2], cylinder({ radius: q.relief, height: h, segments: 16 })),
|
|
660
|
+
);
|
|
266
661
|
g = union(box, ...corners);
|
|
267
662
|
}
|
|
268
663
|
return Object.assign(along(g, q.into, at), { model: s });
|
|
269
664
|
}
|
|
270
665
|
|
|
271
666
|
/**
|
|
272
|
-
* A magnet's solid, standing on z = 0, for an assembly: a disc or a
|
|
667
|
+
* A magnet's solid, standing on z = 0, for an assembly: a disc or a
|
|
668
|
+
* block. @param {string | Magnet} p @param {object} [o] as magnetModel
|
|
273
669
|
* @returns {object} a JSCAD geom3 with .model
|
|
274
670
|
*/
|
|
275
671
|
export function magnet(p, o = {}) {
|
|
276
672
|
const m = magnetModel(p, o);
|
|
277
|
-
const g =
|
|
673
|
+
const g =
|
|
674
|
+
m.shape === 'disc'
|
|
675
|
+
? cylinder({ radius: m.diameter / 2, height: m.thickness, center: [0, 0, m.thickness / 2], segments: 32 })
|
|
676
|
+
: cuboid({ size: [m.length, m.width, m.thickness], center: [0, 0, m.thickness / 2] });
|
|
278
677
|
return Object.assign(g, { model: m });
|
|
279
678
|
}
|