@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/pins.mjs
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// printed peg, is pressed into its hole (it grips) or slides in it (it turns, a hinge pin). Each is a model by name
|
|
4
4
|
// (pinModel: 'snap pin 4x6', 'dowel 3x12', 'filament pin 1.75x12', 'printed pin 4x10'), its hole's fit read from the
|
|
5
5
|
// printer's rules, its mass, what it carries in shear and what the printed hole takes in bearing, and for a snap pin
|
|
6
|
-
// the force to push it in and pull it out. pinHole is the hole to subtract, pin the pin's solid. snapPin, snapSocket
|
|
7
|
-
// snapPinModel draw and size a snap pin from plain figures, as @rulecad/flexures has drawn them since 0.5 (it
|
|
6
|
+
// the force to push it in and pull it out. pinHole is the hole to subtract, pin the pin's solid. snapPin, snapSocket
|
|
7
|
+
// and snapPinModel draw and size a snap pin from plain figures, as @rulecad/flexures has drawn them since 0.5 (it
|
|
8
8
|
// re-exports them from here). Units: mm, N, MPa, grams.
|
|
9
9
|
import jscad from '@jscad/modeling';
|
|
10
10
|
import { teardropHole } from '@rulecad/shapes';
|
|
@@ -17,7 +17,8 @@ import { materialOf, weakest } from './strength.mjs';
|
|
|
17
17
|
const { cuboid, cylinder } = jscad.primitives;
|
|
18
18
|
const { union, subtract } = jscad.booleans;
|
|
19
19
|
const block = (x, y, z, size) => cuboid({ center: [x, y, z], size });
|
|
20
|
-
const n1 = (x) => +x.toFixed(1),
|
|
20
|
+
const n1 = (x) => +x.toFixed(1),
|
|
21
|
+
n2 = (x) => +x.toFixed(2);
|
|
21
22
|
const PINS = pinSet.rules;
|
|
22
23
|
|
|
23
24
|
// ---------- a snap pin from plain figures (as @rulecad/flexures drew it) ----------
|
|
@@ -27,21 +28,44 @@ const PINS = pinSet.rules;
|
|
|
27
28
|
* chamfer by default, so nothing overhangs past the printer's limit; a square back (back 90) holds for good but
|
|
28
29
|
* overhangs by the lip. The halves are modelled as snap hooks of the slot's length, the peg's half-thickness and
|
|
29
30
|
* four fifths of its diameter wide (a half-round's worth), with the lip as the undercut.
|
|
30
|
-
* @param {{ diameter: number, length: number, lip?: number, slot?: number, gap?: number, lead?: number, back?: number,
|
|
31
|
+
* @param {{ diameter: number, length: number, lip?: number, slot?: number, gap?: number, lead?: number, back?: number,
|
|
32
|
+
* head?: number }} p
|
|
31
33
|
* diameter: the peg's; length: the shaft below the barb; lip: the barb's overhang (default 0.4); slot: the split's
|
|
32
34
|
* length down from the tip (default 3 × diameter); gap: the split's width (default 1); lead: the tip cone's angle
|
|
33
35
|
* from the axis, degrees (default 45); back: the barb's back angle (default 45); head: a flange at the foot, its
|
|
34
36
|
* radius past the peg (default diameter / 2)
|
|
35
|
-
* @param {{ union: Function, subtract: Function }} [ops] the booleans to build it with: a design's v.ops, so a design
|
|
37
|
+
* @param {{ union: Function, subtract: Function }} [ops] the booleans to build it with: a design's v.ops, so a design
|
|
38
|
+
* on
|
|
36
39
|
* Manifold gets a pin Manifold reads as a closed solid (JSCAD's own leave seams it can't)
|
|
37
40
|
* @returns {object} a JSCAD geom3 standing on its foot at z = 0
|
|
38
41
|
*/
|
|
39
|
-
export function snapPin(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
42
|
+
export function snapPin(
|
|
43
|
+
{ diameter: d, length: L, lip = 0.4, slot, gap = 1, lead = 45, back = 45, head },
|
|
44
|
+
ops = { union, subtract },
|
|
45
|
+
) {
|
|
46
|
+
const r = d / 2,
|
|
47
|
+
s = slot ?? 3 * d,
|
|
48
|
+
flange = head ?? r,
|
|
49
|
+
seg = 48;
|
|
50
|
+
const fall = back >= 90 ? 0 : lip / Math.tan((back * Math.PI) / 180),
|
|
51
|
+
rise = (r + lip) / Math.tan((lead * Math.PI) / 180);
|
|
52
|
+
const foot = cylinder({ radius: r + flange, height: 2, center: [0, 0, 1], segments: seg }),
|
|
53
|
+
shaft = cylinder({ radius: r, height: L + fall + 0.01, center: [0, 0, 2 + (L + fall) / 2], segments: seg });
|
|
54
|
+
const z0 = 2 + L,
|
|
55
|
+
barbBack = jscad.primitives.cylinderElliptic({
|
|
56
|
+
height: Math.max(fall, 0.01),
|
|
57
|
+
startRadius: [r, r],
|
|
58
|
+
endRadius: [r + lip, r + lip],
|
|
59
|
+
center: [0, 0, z0 + Math.max(fall, 0.01) / 2],
|
|
60
|
+
segments: seg,
|
|
61
|
+
});
|
|
62
|
+
const barbTip = jscad.primitives.cylinderElliptic({
|
|
63
|
+
height: rise,
|
|
64
|
+
startRadius: [r + lip, r + lip],
|
|
65
|
+
endRadius: [0.01, 0.01],
|
|
66
|
+
center: [0, 0, z0 + fall + rise / 2],
|
|
67
|
+
segments: seg,
|
|
68
|
+
});
|
|
45
69
|
const split = block(0, 0, z0 + fall + rise - s / 2 + 1, [2 * (r + lip) + 2, gap, s + 2]);
|
|
46
70
|
return ops.subtract(ops.union(foot, shaft, barbBack, barbTip), split);
|
|
47
71
|
}
|
|
@@ -55,7 +79,10 @@ export function snapPin({ diameter: d, length: L, lip = 0.4, slot, gap = 1, lead
|
|
|
55
79
|
*/
|
|
56
80
|
export function snapSocket({ diameter: d, depth, clearance = printerOf('snapSocket').n('snap_clearance'), wall = 3 }) {
|
|
57
81
|
const Ro = d / 2 + clearance + wall;
|
|
58
|
-
return subtract(
|
|
82
|
+
return subtract(
|
|
83
|
+
block(0, 0, depth / 2, [2 * Ro, 2 * Ro, depth]),
|
|
84
|
+
cylinder({ radius: d / 2 + clearance, height: depth + 2, center: [0, 0, depth / 2], segments: 48 }),
|
|
85
|
+
);
|
|
59
86
|
}
|
|
60
87
|
|
|
61
88
|
// One half of a snap pin as a snap hook: a cantilever of length L, thickness t and width w, deflected by the undercut
|
|
@@ -63,16 +90,38 @@ export function snapSocket({ diameter: d, depth, clearance = printerOf('snapSock
|
|
|
63
90
|
// along the push over a face at α from the beam W = P (μ + tan α) / (1 − μ tan α), Infinity where the face is square
|
|
64
91
|
// or friction locks it (the BASF and Bayer snap-fit design guides).
|
|
65
92
|
function snapHalf({ length: L, thickness: t, width: w, undercut: y, lead, back }, { E, friction: mu = 0.3 }) {
|
|
66
|
-
const stiffness = (E * w * t ** 3) / (4 * L ** 3),
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
const stiffness = (E * w * t ** 3) / (4 * L ** 3),
|
|
94
|
+
strain = (dd) => (3 * t * dd) / (2 * L * L),
|
|
95
|
+
travel = (e) => (2 * L * L * e) / (3 * t);
|
|
96
|
+
const P = stiffness * y,
|
|
97
|
+
push = (deg) => {
|
|
98
|
+
const tan = Math.tan((deg * Math.PI) / 180);
|
|
99
|
+
return deg >= 90 || mu * tan >= 1 ? Infinity : (P * (mu + tan)) / (1 - mu * tan);
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
stiffness,
|
|
103
|
+
strain,
|
|
104
|
+
travel,
|
|
105
|
+
stress: (dd) => E * strain(dd),
|
|
106
|
+
force: P,
|
|
107
|
+
insertion: push(lead),
|
|
108
|
+
removal: push(back),
|
|
109
|
+
holds: !Number.isFinite(push(back)),
|
|
110
|
+
undercut: (e) => travel(e),
|
|
111
|
+
};
|
|
69
112
|
}
|
|
70
|
-
const above = (what, k, v, unit = 'mm') => {
|
|
113
|
+
const above = (what, k, v, unit = 'mm') => {
|
|
114
|
+
if (!(isNum(v) && v > 0))
|
|
115
|
+
throw new Error(`${what}: ${k} is a number above 0${unit ? `, in ${unit}` : ''} (got ${shown(v)})`);
|
|
116
|
+
return v;
|
|
117
|
+
};
|
|
71
118
|
/**
|
|
72
119
|
* A snap pin's forces: its two halves as snap hooks (snapHalf), together.
|
|
73
120
|
* @param {{ diameter: number, lip?: number, slot?: number, gap?: number, lead?: number, back?: number }} p
|
|
74
|
-
* @param {{ E: number, friction?: number }} m E: the plastic's modulus, MPa; friction: μ between barb and hole (default
|
|
75
|
-
*
|
|
121
|
+
* @param {{ E: number, friction?: number }} m E: the plastic's modulus, MPa; friction: μ between barb and hole (default
|
|
122
|
+
* 0.3)
|
|
123
|
+
* @returns {{ stiffness: number, strain: (travel: number) => number, travel: (strain: number) => number,
|
|
124
|
+
* stress: (travel: number) => number,
|
|
76
125
|
* force: number, insertion: number, removal: number, holds: boolean, undercut: (strain: number) => number }}
|
|
77
126
|
* force: to close the halves by the lip, N; insertion and removal: along the pin, N (removal Infinity where the
|
|
78
127
|
* barb's back is square: it holds); undercut: the most the halves may close at a strain
|
|
@@ -80,15 +129,29 @@ const above = (what, k, v, unit = 'mm') => { if (!(isNum(v) && v > 0)) throw new
|
|
|
80
129
|
export function snapPinModel({ diameter: d, lip = 0.4, slot, gap = 1, lead = 45, back = 45 }, m) {
|
|
81
130
|
const what = 'snapPinModel';
|
|
82
131
|
if (!(m && m.E > 0)) throw new Error(`${what}: the material needs a modulus E above 0 MPa (got ${m?.E})`);
|
|
83
|
-
above(what, 'diameter', d);
|
|
132
|
+
above(what, 'diameter', d);
|
|
133
|
+
above(what, 'lip', lip);
|
|
84
134
|
if (slot !== undefined) above(what, 'slot', slot);
|
|
85
|
-
if (!(isNum(gap) && gap >= 0 && gap < d))
|
|
86
|
-
|
|
87
|
-
|
|
135
|
+
if (!(isNum(gap) && gap >= 0 && gap < d))
|
|
136
|
+
throw new Error(
|
|
137
|
+
`${what}: gap is the split's width, 0 mm or more and narrower than the ${mm(d)} mm peg (got ${shown(gap)})`,
|
|
138
|
+
);
|
|
139
|
+
const half = snapHalf(
|
|
140
|
+
{ length: slot ?? 3 * d, thickness: (d - gap) / 2, width: 0.8 * d, undercut: lip, lead, back },
|
|
141
|
+
m,
|
|
142
|
+
);
|
|
143
|
+
return {
|
|
144
|
+
...half,
|
|
145
|
+
stiffness: 2 * half.stiffness,
|
|
146
|
+
force: 2 * half.force,
|
|
147
|
+
insertion: 2 * half.insertion,
|
|
148
|
+
removal: 2 * half.removal,
|
|
149
|
+
};
|
|
88
150
|
}
|
|
89
151
|
|
|
90
152
|
// ---------- pins by name ----------
|
|
91
|
-
/** The kinds of pin there are: a printed snap pin, a bought steel dowel, a cut length of filament, a printed plain
|
|
153
|
+
/** The kinds of pin there are: a printed snap pin, a bought steel dowel, a cut length of filament, a printed plain
|
|
154
|
+
* pin. */
|
|
92
155
|
export const PIN_KINDS = ['snap', 'dowel', 'filament', 'printed'];
|
|
93
156
|
/** The fits a plain pin takes in its hole: press (it grips) and slip (it turns, a hinge pin). */
|
|
94
157
|
export const PIN_FITS = ['press', 'slip'];
|
|
@@ -97,59 +160,106 @@ export const PIN_FITS = ['press', 'slip'];
|
|
|
97
160
|
* @type {string}
|
|
98
161
|
*/
|
|
99
162
|
export const PIN_GRAMMAR = [
|
|
100
|
-
'pin = kind diameter "x" length { word } snap pin 4x6, dowel 3x12, filament pin 1.75x12,
|
|
163
|
+
'pin = kind diameter "x" length { word } snap pin 4x6, dowel 3x12, filament pin 1.75x12, ' +
|
|
164
|
+
'printed pin 4x10',
|
|
101
165
|
'kind = "snap pin" | "dowel" | "filament pin" | "printed pin" ("pins" and "dowel pin" are read too)',
|
|
102
|
-
|
|
103
|
-
'length = number [ "mm" ] mm: a snap pin\'s shaft from its foot to its barb; a
|
|
166
|
+
"diameter = number mm: the peg's, below a snap pin's barb",
|
|
167
|
+
'length = number [ "mm" ] mm: a snap pin\'s shaft from its foot to its barb; a ' +
|
|
168
|
+
"plain pin's whole length",
|
|
104
169
|
'word = "barb" number a snap pin\'s barb past its peg (default 0.4)',
|
|
105
|
-
' | "ISO 8734" | "ISO 2338" a dowel\'s standard: hardened and ground (the
|
|
170
|
+
' | "ISO 8734" | "ISO 2338" a dowel\'s standard: hardened and ground (the ' +
|
|
171
|
+
'default), or unhardened',
|
|
106
172
|
].join('\n');
|
|
107
|
-
const KIND_WORDS = [
|
|
173
|
+
const KIND_WORDS = [
|
|
174
|
+
[/^snap\s*pins?$/i, 'snap'],
|
|
175
|
+
[/^dowel(?:\s*pins?)?s?$/i, 'dowel'],
|
|
176
|
+
[/^filament(?:\s*pins?)?$/i, 'filament'],
|
|
177
|
+
[/^printed\s*pins?$/i, 'printed'],
|
|
178
|
+
];
|
|
108
179
|
const STANDARDS = { 'iso 8734': 'ISO 8734', 'iso 2338': 'ISO 2338' };
|
|
109
180
|
|
|
110
181
|
/**
|
|
111
182
|
* A pin's name read by the grammar.
|
|
112
|
-
* @param {string} name 'snap pin 4x6', 'snap pin 2.5x4 barb 0.3', 'dowel 3x12', 'dowel 3x12 ISO 2338', 'filament pin
|
|
113
|
-
*
|
|
183
|
+
* @param {string} name 'snap pin 4x6', 'snap pin 2.5x4 barb 0.3', 'dowel 3x12', 'dowel 3x12 ISO 2338', 'filament pin
|
|
184
|
+
* 1.75x12', 'printed pin 4x10'
|
|
185
|
+
* @returns {{ kind: 'snap' | 'dowel' | 'filament' | 'printed', diameter: number, length: number, barb: number | null,
|
|
186
|
+
* standard: string | null }}
|
|
114
187
|
*/
|
|
115
188
|
export function parsePin(name) {
|
|
116
|
-
const what = 'pin name',
|
|
189
|
+
const what = 'pin name',
|
|
190
|
+
help =
|
|
191
|
+
"A pin is its kind, then diameter x length in mm: 'snap pin 4x6', 'dowel 3x12', 'filament pin " +
|
|
192
|
+
"1.75x12', 'printed pin 4x10'";
|
|
117
193
|
if (typeof name !== 'string' || !name.trim()) throw new Error(`${what}: give a name, not ${shown(name)}. ${help}`);
|
|
118
194
|
const t = /^\s*([a-z][a-z\s]*?)\s+(\d*\.?\d+)\s*[x×*]\s*(\d*\.?\d+)\s*(?:mm\b)?(.*)$/i.exec(name);
|
|
119
195
|
const kind = t && KIND_WORDS.find(([re]) => re.test(t[1].trim()))?.[1];
|
|
120
196
|
if (!t || !kind) throw new Error(`${what}: "${name}" is no pin. ${help}`);
|
|
121
|
-
const diameter = Number(t[2]),
|
|
197
|
+
const diameter = Number(t[2]),
|
|
198
|
+
length = Number(t[3]);
|
|
122
199
|
if (!(diameter > 0 && length > 0)) throw new Error(`${what}: "${name}": a pin's diameter and length are above 0 mm`);
|
|
123
|
-
let rest_ = t[4].trim().toLowerCase(),
|
|
200
|
+
let rest_ = t[4].trim().toLowerCase(),
|
|
201
|
+
barb = null,
|
|
202
|
+
standard = null;
|
|
124
203
|
const b = /\bbarb\s+(\d*\.?\d+)\s*(?:mm\b)?/.exec(rest_);
|
|
125
|
-
if (b) {
|
|
204
|
+
if (b) {
|
|
205
|
+
if (kind !== 'snap') throw new Error(`${what}: "${name}": only a snap pin has a barb`);
|
|
206
|
+
barb = Number(b[1]);
|
|
207
|
+
if (!(barb > 0)) throw new Error(`${what}: "${name}": a barb is above 0 mm`);
|
|
208
|
+
rest_ = rest_.replace(b[0], ' ');
|
|
209
|
+
}
|
|
126
210
|
const s = /\biso\s*(8734|2338)\b/.exec(rest_);
|
|
127
|
-
if (s) {
|
|
211
|
+
if (s) {
|
|
212
|
+
if (kind !== 'dowel') throw new Error(`${what}: "${name}": only a dowel is bought to a standard`);
|
|
213
|
+
standard = STANDARDS[`iso ${s[1]}`];
|
|
214
|
+
rest_ = rest_.replace(s[0], ' ');
|
|
215
|
+
}
|
|
128
216
|
const left = rest_.split(/[\s,]+/).filter((w) => w && w !== 'pin' && w !== 'pins');
|
|
129
|
-
if (left.length)
|
|
130
|
-
|
|
217
|
+
if (left.length)
|
|
218
|
+
throw new Error(
|
|
219
|
+
`${what}: "${name}": nothing is called "${left.join(' ')}". After the size come only "barb 0.4" (a ` +
|
|
220
|
+
`snap pin) or "ISO 8734" / "ISO 2338" (a dowel)`,
|
|
221
|
+
);
|
|
222
|
+
return { kind, diameter, length, barb, standard: kind === 'dowel' ? (standard ?? 'ISO 8734') : null };
|
|
131
223
|
}
|
|
132
224
|
/** Whether a text is a pin's name, by the grammar. @param {unknown} name @returns {boolean} */
|
|
133
|
-
export const isPinName = (name) => {
|
|
225
|
+
export const isPinName = (name) => {
|
|
226
|
+
try {
|
|
227
|
+
parsePin(/** @type {string} */ (name));
|
|
228
|
+
return true;
|
|
229
|
+
} catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
134
233
|
/** A pin's name in its one spelling. */
|
|
135
|
-
const pinName = (p) =>
|
|
234
|
+
const pinName = (p) =>
|
|
235
|
+
(p.kind === 'snap' ? 'snap pin' : p.kind === 'dowel' ? 'dowel' : `${p.kind} pin`) +
|
|
236
|
+
` ${mm(p.diameter)}x${mm(p.length)}` +
|
|
237
|
+
(p.barb != null && p.barb !== 0.4 ? ` barb ${mm(p.barb)}` : '') +
|
|
238
|
+
(p.standard && p.standard !== 'ISO 8734' ? ` ${p.standard}` : '');
|
|
136
239
|
const pinRest = (k) => rest(`pins.${k}`, PINS[k]);
|
|
137
|
-
const nearest = (list, x) => {
|
|
240
|
+
const nearest = (list, x) => {
|
|
241
|
+
const below = list.filter((v) => v < x).at(-1),
|
|
242
|
+
over = list.find((v) => v > x);
|
|
243
|
+
return [below, over].filter((v) => v != null);
|
|
244
|
+
};
|
|
138
245
|
|
|
139
246
|
/**
|
|
140
|
-
* @typedef {{ kind: 'pin', type: 'snap' | 'dowel' | 'filament' | 'printed', name: string, said: string,
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
247
|
+
* @typedef {{ kind: 'pin', type: 'snap' | 'dowel' | 'filament' | 'printed', name: string, said: string,
|
|
248
|
+
* diameter: number, length: number,
|
|
249
|
+
* made: 'bought' | 'cut' | 'printed', standard: string | null, fit: 'snap' | 'press' | 'slip', material: string,
|
|
250
|
+
* pinMaterial: string, hole:
|
|
251
|
+
* { diameter: number, nominal: number, comp: number, clearance: number, into: string, axis: 'x' | 'y' | 'z',
|
|
252
|
+
* teardrop: boolean, rules: string[] }, snap: { lip: number, slot: number, gap: number, lead: number, back: number,
|
|
253
|
+
* head: number, insertion: number, removal: number, force: number, strain: number, holds: boolean } | null, grams:
|
|
254
|
+
* number, shear: number, bearing: number, pull: number | null, load: number | null, margin: number | null, governs:
|
|
255
|
+
* string | null, thickness: number | null, rests: object[], findings: object[] }} Pin diameter, length: the pin's (a
|
|
256
|
+
* snap pin's length is its shaft, foot to barb); made: bought (a dowel), cut (filament) or printed; fit: how it sits
|
|
257
|
+
* in its hole; material: the part's plastic, which the pin bears on; pinMaterial: the pin's own; hole: what to draw
|
|
258
|
+
* for it (diameter as drawn; nominal: the pin's; comp: hole compensation added; clearance: added across past that,
|
|
259
|
+
* less than 0 for a press); snap: a snap pin's figures and forces (insertion and removal along the pin, N; force: to
|
|
260
|
+
* close the halves; strain: at the halves' roots, closed by the barb); shear: what the pin carries across its shear
|
|
261
|
+
* planes, N; bearing: what the printed hole takes before it crushes, N; pull: what a snap pin holds along its axis,
|
|
262
|
+
* N; load and margin: the load given (across the pin, N) and the least of shear, bearing and pull over it
|
|
153
263
|
*/
|
|
154
264
|
|
|
155
265
|
/**
|
|
@@ -158,9 +268,10 @@ const nearest = (list, x) => { const below = list.filter((v) => v < x).at(-1), o
|
|
|
158
268
|
* thickness it goes in stands proud; a snap pin's shaft shorter than the thickness never lets its barb out, and one
|
|
159
269
|
* more than fixings.snap_play longer rattles.
|
|
160
270
|
* @param {string | Pin} p a pin's name (see PIN_GRAMMAR) or its model
|
|
161
|
-
* @param {{ fit?: 'press' | 'slip', printer?: object, material?: string | object, pinMaterial?: string | object,
|
|
162
|
-
*
|
|
163
|
-
*
|
|
271
|
+
* @param {{ fit?: 'press' | 'slip', printer?: object, material?: string | object, pinMaterial?: string | object,
|
|
272
|
+
* load?: number, pull?: number,
|
|
273
|
+
* thickness?: number, grip?: number, planes?: number, axis?: 'x' | 'y' | 'z', into?: string, anyLength?: boolean,
|
|
274
|
+
* sets?: object, slot?: number, gap?: number, lead?: number, back?: number, head?: number, friction?: number }} [o]
|
|
164
275
|
* fit: a plain pin's, press (the default) or slip; printer: the printer's rule set or values (default the X1C);
|
|
165
276
|
* material: the part's plastic (default PLA); pinMaterial: a printed or filament pin's (default the part's);
|
|
166
277
|
* load: across the pin, N, which its shear and the hole's bearing are held to with fixings.load_margin; pull: along a
|
|
@@ -172,57 +283,183 @@ const nearest = (list, x) => { const below = list.filter((v) => v < x).at(-1), o
|
|
|
172
283
|
*/
|
|
173
284
|
export function pinModel(p, o = {}) {
|
|
174
285
|
const what = 'pinModel';
|
|
175
|
-
optionsOf(what, o,
|
|
286
|
+
optionsOf(what, o, "{ fit: 'press', load: 20 }");
|
|
176
287
|
if (p && typeof p === 'object' && p.kind === 'pin') return p;
|
|
177
|
-
const n = parsePin(p),
|
|
178
|
-
|
|
179
|
-
|
|
288
|
+
const n = parsePin(p),
|
|
289
|
+
pr = printerOf(what, o.printer),
|
|
290
|
+
dir = directionOf(what, o, '-z'),
|
|
291
|
+
out = [],
|
|
292
|
+
rests = [];
|
|
293
|
+
const mat = materialOf(what, o.material ?? 'pla', o.sets),
|
|
294
|
+
pinMat = n.kind === 'dowel' ? null : materialOf(what, o.pinMaterial ?? o.material ?? 'pla', o.sets);
|
|
295
|
+
const { f: weak } = weakest(mat),
|
|
296
|
+
d = n.diameter,
|
|
297
|
+
L = n.length;
|
|
180
298
|
// The pin itself: a dowel held to what is sold, filament to its own diameter, a printed pin to what prints
|
|
181
299
|
if (n.kind === 'dowel') {
|
|
182
|
-
const ds = PINS.dowel_diameters.value,
|
|
183
|
-
|
|
184
|
-
if (!
|
|
300
|
+
const ds = PINS.dowel_diameters.value,
|
|
301
|
+
ls = PINS.dowel_lengths.value;
|
|
302
|
+
if (!ds.includes(d))
|
|
303
|
+
throw new Error(
|
|
304
|
+
`${what}: no ${n.standard} dowel is ${mm(d)} mm across: the nearest ` +
|
|
305
|
+
`${nearest(ds, d).length > 1 ? 'are' : 'is'} ${nearest(ds, d).map(mm).join(' and ')} mm ` +
|
|
306
|
+
`(pins.dowel_diameters: ${ds.map(mm).join(', ')})`,
|
|
307
|
+
);
|
|
308
|
+
if (!ls.includes(L) && !o.anyLength)
|
|
309
|
+
throw new Error(
|
|
310
|
+
`${what}: a dowel is not sold ${mm(L)} mm long: the nearest ` +
|
|
311
|
+
`${nearest(ls, L).length > 1 ? 'are' : 'is'} ${nearest(ls, L).map(mm).join(' and ')} mm ` +
|
|
312
|
+
`(pins.dowel_lengths). For a length you know you can buy, pass { anyLength: true }`,
|
|
313
|
+
);
|
|
185
314
|
rests.push(pinRest('dowel_diameters'), pinRest('dowel_lengths'), pinRest('dowel_tolerance'));
|
|
186
315
|
} else if (n.kind === 'filament') {
|
|
187
|
-
if (d !== PINS.filament_diameter.value)
|
|
316
|
+
if (d !== PINS.filament_diameter.value)
|
|
317
|
+
throw new Error(
|
|
318
|
+
`${what}: a filament pin is the printer's filament, ${mm(PINS.filament_diameter.value)} mm across ` +
|
|
319
|
+
`(pins.filament_diameter), not ${mm(d)} mm: for a thicker peg, name a printed pin or a dowel`,
|
|
320
|
+
);
|
|
188
321
|
rests.push(pinRest('filament_diameter'), pinRest('filament_tolerance'));
|
|
189
|
-
} else if (d < DEFAULTS.pin_least.value)
|
|
190
|
-
|
|
322
|
+
} else if (d < DEFAULTS.pin_least.value)
|
|
323
|
+
throw new Error(
|
|
324
|
+
`${what}: a ${n.kind === 'snap' ? 'snap' : 'printed'} pin ${mm(d)} mm across is under ` +
|
|
325
|
+
`fixings.pin_least, ${mm(DEFAULTS.pin_least.value)} mm: thinner, it is a few lines of plastic and ` +
|
|
326
|
+
`breaks as it goes in. Use filament or a dowel`,
|
|
327
|
+
);
|
|
328
|
+
if (n.kind === 'snap' && o.fit != null)
|
|
329
|
+
throw new Error(`${what}: a snap pin's fit is its socket's (x1c.snap_clearance): give fit only for a plain pin`);
|
|
191
330
|
const fit = n.kind === 'snap' ? 'snap' : oneOf(what, 'fit', o.fit ?? 'press', PIN_FITS);
|
|
192
331
|
|
|
193
332
|
// The hole: a snap pin's socket is drawn as it is (the peg plus snap_clearance each side); a plain pin's is the pin,
|
|
194
333
|
// plus the hole compensation a printed hole needs, less pin_press or plus pin_slip
|
|
195
334
|
let hole;
|
|
196
335
|
if (n.kind === 'snap') {
|
|
197
|
-
const c = pr.n('snap_clearance');
|
|
336
|
+
const c = pr.n('snap_clearance');
|
|
337
|
+
rests.push(pr.rest('snap_clearance'));
|
|
198
338
|
hole = { diameter: r3(d + 2 * c), nominal: d, comp: 0, clearance: r3(2 * c), rules: [pr.cite('snap_clearance')] };
|
|
199
|
-
out.push(
|
|
339
|
+
out.push(
|
|
340
|
+
finding(
|
|
341
|
+
'info',
|
|
342
|
+
`${pinName(n)}'s socket drawn ${mm(hole.diameter)} mm: the ${mm(d)} mm peg plus ` +
|
|
343
|
+
`${pr.cite('snap_clearance')} ${mm(c)} mm each side (` +
|
|
344
|
+
(pr.rest('snap_clearance').kind === 'estimate'
|
|
345
|
+
? 'an estimate until the holds coupon measures it'
|
|
346
|
+
: `${pr.rest('snap_clearance').kind}`) +
|
|
347
|
+
`), as drawn, so the split halves close to let the barb through`,
|
|
348
|
+
'pin.hole',
|
|
349
|
+
{
|
|
350
|
+
values: { diameter: hole.diameter, nominal: d, clearance: hole.clearance },
|
|
351
|
+
refs: { pin: pinName(n), rule: pr.cite('snap_clearance') },
|
|
352
|
+
},
|
|
353
|
+
),
|
|
354
|
+
);
|
|
200
355
|
} else {
|
|
201
|
-
const comp = pr.n('hole_comp'),
|
|
356
|
+
const comp = pr.n('hole_comp'),
|
|
357
|
+
k = fit === 'press' ? 'pin_press' : 'pin_slip',
|
|
358
|
+
c = pr.n(k),
|
|
359
|
+
clearance = fit === 'press' ? -c : c;
|
|
202
360
|
rests.push(pr.rest('hole_comp'), pr.rest(k));
|
|
203
|
-
hole = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
361
|
+
hole = {
|
|
362
|
+
diameter: r3(d + comp + clearance),
|
|
363
|
+
nominal: d,
|
|
364
|
+
comp,
|
|
365
|
+
clearance: r3(clearance),
|
|
366
|
+
rules: [pr.cite('hole_comp'), pr.cite(k)],
|
|
367
|
+
};
|
|
368
|
+
out.push(
|
|
369
|
+
finding(
|
|
370
|
+
'info',
|
|
371
|
+
`${pinName(n)}'s ${fit} hole drawn ${mm(hole.diameter)} mm: the ${mm(d)} mm pin, plus ` +
|
|
372
|
+
`${pr.cite('hole_comp')} ${mm(comp)} mm across since a printed hole comes out small, ` +
|
|
373
|
+
`${fit === 'press' ? 'less' : 'plus'} ${pr.cite(k)} ${mm(c)} mm (` +
|
|
374
|
+
`${pr.figure(k)?.kind ?? pr.rest(k).kind}) so it ${fit === 'press' ? 'grips' : 'turns'}`,
|
|
375
|
+
'pin.hole',
|
|
376
|
+
{
|
|
377
|
+
values: { diameter: hole.diameter, nominal: d, comp, clearance: hole.clearance },
|
|
378
|
+
refs: { pin: pinName(n), fit, rule: pr.cite(k) },
|
|
379
|
+
},
|
|
380
|
+
),
|
|
381
|
+
);
|
|
382
|
+
if (n.kind === 'filament')
|
|
383
|
+
out.push(
|
|
384
|
+
finding(
|
|
385
|
+
'info',
|
|
386
|
+
`filament is ${mm(d)} ± ${mm(PINS.filament_tolerance.value)} mm (pins.filament_tolerance, ` +
|
|
387
|
+
`community): measure the reel the pin is cut from, as a ${fit} fit is closer than that`,
|
|
388
|
+
'pin.tolerance',
|
|
389
|
+
{ values: { tolerance: PINS.filament_tolerance.value } },
|
|
390
|
+
),
|
|
391
|
+
);
|
|
392
|
+
if (n.kind === 'printed')
|
|
393
|
+
out.push(
|
|
394
|
+
finding(
|
|
395
|
+
'info',
|
|
396
|
+
`a printed pin is itself printed, standing, so its size is as close as the printer's: try the ` +
|
|
397
|
+
`${fit} fit before relying on it`,
|
|
398
|
+
'pin.printed',
|
|
399
|
+
),
|
|
400
|
+
);
|
|
207
401
|
}
|
|
208
|
-
hole.into = dir.into;
|
|
209
|
-
|
|
402
|
+
hole.into = dir.into;
|
|
403
|
+
hole.axis = dir.axis;
|
|
404
|
+
hole.teardrop = dir.across;
|
|
405
|
+
out.push(
|
|
406
|
+
finding(
|
|
407
|
+
'pass',
|
|
408
|
+
dir.across
|
|
409
|
+
? `${said(dir.into)}, the hole is a teardrop: a 45° roof, so it prints with no support`
|
|
410
|
+
: `${said(dir.into)}, a round hole prints as drawn`,
|
|
411
|
+
'pin.printable',
|
|
412
|
+
{ values: { into: dir.into } },
|
|
413
|
+
),
|
|
414
|
+
);
|
|
210
415
|
|
|
211
416
|
// A snap pin's barb and its forces
|
|
212
|
-
let snap = null,
|
|
417
|
+
let snap = null,
|
|
418
|
+
solid = null;
|
|
213
419
|
if (n.kind === 'snap') {
|
|
214
|
-
const lip = n.barb ?? 0.4,
|
|
215
|
-
|
|
216
|
-
|
|
420
|
+
const lip = n.barb ?? 0.4,
|
|
421
|
+
sp = {
|
|
422
|
+
diameter: d,
|
|
423
|
+
length: L,
|
|
424
|
+
lip,
|
|
425
|
+
slot: o.slot ?? 3 * d,
|
|
426
|
+
gap: o.gap ?? 1,
|
|
427
|
+
lead: o.lead ?? 45,
|
|
428
|
+
back: o.back ?? 45,
|
|
429
|
+
head: o.head ?? d / 2,
|
|
430
|
+
};
|
|
431
|
+
const sm = snapPinModel(sp, { E: mat.modulus.value, ...(o.friction != null ? { friction: o.friction } : {}) }),
|
|
432
|
+
strain = sm.strain(lip);
|
|
433
|
+
snap = {
|
|
434
|
+
...sp,
|
|
435
|
+
insertion: n2(sm.insertion),
|
|
436
|
+
removal: Number.isFinite(sm.removal) ? n2(sm.removal) : Infinity,
|
|
437
|
+
force: n2(sm.force),
|
|
438
|
+
strain: +strain.toFixed(4),
|
|
439
|
+
holds: sm.holds,
|
|
440
|
+
};
|
|
217
441
|
rests.push(rest(mat.modulus.name, mat.modulus));
|
|
218
|
-
out.push(
|
|
442
|
+
out.push(
|
|
443
|
+
finding(
|
|
444
|
+
'info',
|
|
445
|
+
`${pinName(n)}: ${mm(snap.insertion)} N to push in and ` +
|
|
446
|
+
(sm.holds ? 'it holds for good (a square back)' : `${mm(snap.removal)} N to pull out`) +
|
|
447
|
+
`, its halves bending ${mm(n2(strain * 100))}% at their roots as the ${mm(lip)} mm barb closes them ` +
|
|
448
|
+
`(two snap hooks, 3ty / 2L², on ${mat.modulus.name} ${mm(mat.modulus.value)} MPa, μ ` +
|
|
449
|
+
`${mm(o.friction ?? 0.3)})`,
|
|
450
|
+
'pin.snap',
|
|
451
|
+
{ values: { insertion: snap.insertion, removal: snap.removal, strain: snap.strain } },
|
|
452
|
+
),
|
|
453
|
+
);
|
|
219
454
|
solid = snapPin(sp);
|
|
220
455
|
}
|
|
221
456
|
|
|
222
457
|
// Mass: a solid's volume by its density
|
|
223
|
-
const area = (Math.PI * d * d) / 4,
|
|
458
|
+
const area = (Math.PI * d * d) / 4,
|
|
459
|
+
density = n.kind === 'dowel' ? { ...DEFAULTS.steel_density, name: 'fixings.steel_density' } : pinMat.density;
|
|
224
460
|
if (!density) throw new Error(`${what}: ${pinMat.name} has no density in its rule set, so the pin cannot be weighed`);
|
|
225
|
-
const volume = solid ? jscad.measurements.measureVolume(solid) : area * L,
|
|
461
|
+
const volume = solid ? jscad.measurements.measureVolume(solid) : area * L,
|
|
462
|
+
grams = +((volume * density.value) / 1000).toFixed(3);
|
|
226
463
|
rests.push(rest(density.name, density));
|
|
227
464
|
|
|
228
465
|
// What it fits: a plain pin no longer than the part; a snap pin's shaft as long as the part, and a little more
|
|
@@ -231,70 +468,200 @@ export function pinModel(p, o = {}) {
|
|
|
231
468
|
thickness = positive(what, 'thickness', o.thickness);
|
|
232
469
|
if (n.kind === 'snap') {
|
|
233
470
|
const play = DEFAULTS.snap_play.value;
|
|
234
|
-
if (L < thickness - 1e-9)
|
|
235
|
-
|
|
471
|
+
if (L < thickness - 1e-9)
|
|
472
|
+
throw new Error(
|
|
473
|
+
`${what}: ${pinName(n)}'s shaft is ${mm(L)} mm long, and the parts it goes through are ` +
|
|
474
|
+
`${mm(thickness)} mm thick: it is too short for its part, and the barb never clicks out past the ` +
|
|
475
|
+
`far face. Use a shaft of ${mm(thickness)} mm to ${mm(thickness + play)} mm`,
|
|
476
|
+
);
|
|
477
|
+
if (L > thickness + play + 1e-9)
|
|
478
|
+
throw new Error(
|
|
479
|
+
`${what}: ${pinName(n)}'s shaft is ${mm(L)} mm long, and the parts it goes through are ` +
|
|
480
|
+
`${mm(thickness)} mm thick: it is too long for its part, so the barb clicks out ` +
|
|
481
|
+
`${mm(r3(L - thickness))} mm past the far face and the pin rattles (fixings.snap_play allows ` +
|
|
482
|
+
`${mm(play)} mm). Use a shaft of ${mm(thickness)} mm to ${mm(thickness + play)} mm`,
|
|
483
|
+
);
|
|
236
484
|
rests.push(rest('fixings.snap_play', DEFAULTS.snap_play));
|
|
237
|
-
out.push(
|
|
485
|
+
out.push(
|
|
486
|
+
finding(
|
|
487
|
+
'pass',
|
|
488
|
+
`${pinName(n)}'s ${mm(L)} mm shaft through ${mm(thickness)} mm of parts: the barb clicks out ` +
|
|
489
|
+
`${mm(r3(L - thickness))} mm past the far face (fixings.snap_play allows ${mm(play)} mm)`,
|
|
490
|
+
'pin.length',
|
|
491
|
+
{ values: { length: L, thickness } },
|
|
492
|
+
),
|
|
493
|
+
);
|
|
238
494
|
} else {
|
|
239
495
|
if (L > thickness + 1e-9) {
|
|
240
496
|
const fits = n.kind === 'dowel' ? PINS.dowel_lengths.value.filter((x) => x <= thickness).at(-1) : null;
|
|
241
|
-
throw new Error(
|
|
497
|
+
throw new Error(
|
|
498
|
+
`${what}: ${pinName(n)} is ${mm(L)} mm long, and the parts it goes in hold ${mm(thickness)} mm of ` +
|
|
499
|
+
`it: it is too long for its part, and stands ${mm(r3(L - thickness))} mm proud. ` +
|
|
500
|
+
(fits != null
|
|
501
|
+
? `The longest dowel that fits is ${mm(fits)} mm (pins.dowel_lengths)`
|
|
502
|
+
: `Cut it to ${mm(thickness)} mm`) +
|
|
503
|
+
`, or make the parts thicker`,
|
|
504
|
+
);
|
|
242
505
|
}
|
|
243
|
-
out.push(
|
|
506
|
+
out.push(
|
|
507
|
+
finding(
|
|
508
|
+
'pass',
|
|
509
|
+
`${pinName(n)}, ${mm(L)} mm long, in ${mm(thickness)} mm of parts: it stands proud of nothing`,
|
|
510
|
+
'pin.length',
|
|
511
|
+
{ values: { length: L, thickness } },
|
|
512
|
+
),
|
|
513
|
+
);
|
|
244
514
|
}
|
|
245
515
|
}
|
|
246
516
|
|
|
247
517
|
// Strength: the pin's shear across its planes, and the printed hole's bearing on its grip; a snap pin also its pull
|
|
248
518
|
const planes = o.planes ?? 1;
|
|
249
|
-
if (!(Number.isInteger(planes) && planes >= 1))
|
|
250
|
-
|
|
519
|
+
if (!(Number.isInteger(planes) && planes >= 1))
|
|
520
|
+
throw new Error(
|
|
521
|
+
`${what}: planes is how many shear planes the pin crosses, a whole number from 1 (two parts; got ` +
|
|
522
|
+
`${shown(o.planes)})`,
|
|
523
|
+
);
|
|
524
|
+
const grip = o.grip != null ? positive(what, 'grip', o.grip) : (thickness ?? L) / 2,
|
|
525
|
+
ratio = DEFAULTS.shear_ratio.value;
|
|
251
526
|
let tau, tauSays;
|
|
252
|
-
if (n.kind === 'dowel') {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
527
|
+
if (n.kind === 'dowel') {
|
|
528
|
+
tau = PINS.dowel_shear.value;
|
|
529
|
+
tauSays = `pins.dowel_shear ${mm(tau)} MPa, an estimate that understates a hardened pin`;
|
|
530
|
+
rests.push(pinRest('dowel_shear'));
|
|
531
|
+
} else {
|
|
532
|
+
// (filament: the strand's own strength; a printed pin stands, so its shear plane is a layer's)
|
|
533
|
+
const along_ = n.kind === 'filament' ? pinMat.strength : weakest(pinMat).f;
|
|
534
|
+
tau = along_.value * ratio;
|
|
535
|
+
tauSays = `${along_.name} ${mm(along_.value)} MPa × fixings.shear_ratio ${mm(+ratio.toFixed(3))}, an estimate`;
|
|
536
|
+
rests.push(rest(along_.name, along_), rest('fixings.shear_ratio', DEFAULTS.shear_ratio));
|
|
256
537
|
}
|
|
257
|
-
const shearArea = n.kind === 'snap' ? area - (o.gap ?? 1) * d : area,
|
|
538
|
+
const shearArea = n.kind === 'snap' ? area - (o.gap ?? 1) * d : area,
|
|
539
|
+
shear = n1(tau * shearArea * planes),
|
|
540
|
+
bearing = n1(weak.value * d * grip);
|
|
258
541
|
rests.push(rest(weak.name, weak));
|
|
259
542
|
let pull = null;
|
|
260
|
-
if (snap) {
|
|
543
|
+
if (snap) {
|
|
544
|
+
const tensile = n1(weakest(pinMat).f.value * shearArea);
|
|
545
|
+
pull = Number.isFinite(snap.removal) ? Math.min(snap.removal, tensile) : tensile;
|
|
546
|
+
}
|
|
261
547
|
const caps = { shear, bearing, ...(pull != null ? { pull } : {}) };
|
|
262
|
-
const load = o.load != null ? positive(what, 'load (across the pin, in N)', o.load) : null,
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
548
|
+
const load = o.load != null ? positive(what, 'load (across the pin, in N)', o.load) : null,
|
|
549
|
+
pullLoad = o.pull != null ? positive(what, 'pull (along the pin, in N)', o.pull) : null;
|
|
550
|
+
if (pullLoad != null && !snap)
|
|
551
|
+
throw new Error(
|
|
552
|
+
`${what}: pull is along a snap pin: a plain pin holds by its press fit, which these sums do not give, ` +
|
|
553
|
+
`so hold it along by a shoulder or glue`,
|
|
554
|
+
);
|
|
555
|
+
const margins = {
|
|
556
|
+
...(load != null ? { shear: n2(shear / load), bearing: n2(bearing / load) } : {}),
|
|
557
|
+
...(pullLoad != null ? { pull: n2(pull / pullLoad) } : {}),
|
|
558
|
+
};
|
|
559
|
+
const governs = Object.keys(margins).length ? Object.entries(margins).sort((x, y) => x[1] - y[1])[0][0] : null,
|
|
560
|
+
margin = governs ? margins[governs] : null;
|
|
561
|
+
const want = DEFAULTS.load_margin.value,
|
|
562
|
+
says =
|
|
563
|
+
`${pinName(n)} carries ${mm(shear)} N in shear (${planes} plane${planes > 1 ? 's' : ''}, ${tauSays}); ` +
|
|
564
|
+
`the printed hole takes ${mm(bearing)} N in bearing on ${mm(grip)} mm of grip (${weak.name} ` +
|
|
565
|
+
`${mm(weak.value)} MPa, taken as what it bears: an estimate)` +
|
|
566
|
+
(pull != null ? `; it holds ${mm(pull)} N along` : '');
|
|
567
|
+
if (margin == null)
|
|
568
|
+
out.push(finding('info', `${says}: give load to have it checked`, 'pin.strength', { values: caps }));
|
|
569
|
+
else
|
|
570
|
+
out.push(
|
|
571
|
+
finding(
|
|
572
|
+
margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail',
|
|
573
|
+
`${says}: ` +
|
|
574
|
+
(load != null ? `${mm(load)} N across` : '') +
|
|
575
|
+
(load != null && pullLoad != null ? ' and ' : '') +
|
|
576
|
+
(pullLoad != null ? `${mm(pullLoad)} N along` : '') +
|
|
577
|
+
` leaves ${mm(margin)} times over in ${governs}` +
|
|
578
|
+
(margin >= want
|
|
579
|
+
? ''
|
|
580
|
+
: margin >= 1
|
|
581
|
+
? `, under the ${mm(want)} times fixings.load_margin asks`
|
|
582
|
+
: ': it gives way'),
|
|
583
|
+
'pin.strength',
|
|
584
|
+
{ values: { ...caps, load, pull: pullLoad, margin, governs } },
|
|
585
|
+
),
|
|
586
|
+
);
|
|
270
587
|
rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
|
|
271
588
|
out.push(finding('info', `${pinName(n)} weighs ${mm(grams)} g`, 'pin.mass', { values: { grams } }));
|
|
272
|
-
return {
|
|
273
|
-
|
|
589
|
+
return {
|
|
590
|
+
kind: 'pin',
|
|
591
|
+
type: n.kind,
|
|
592
|
+
name: pinName(n),
|
|
593
|
+
said: String(p),
|
|
594
|
+
diameter: d,
|
|
595
|
+
length: L,
|
|
596
|
+
made: n.kind === 'dowel' ? 'bought' : n.kind === 'filament' ? 'cut' : 'printed',
|
|
597
|
+
standard: n.standard,
|
|
598
|
+
fit,
|
|
599
|
+
material: mat.name,
|
|
600
|
+
pinMaterial: pinMat ? pinMat.name : 'steel',
|
|
601
|
+
hole,
|
|
602
|
+
snap,
|
|
603
|
+
grams,
|
|
604
|
+
shear,
|
|
605
|
+
bearing,
|
|
606
|
+
pull,
|
|
607
|
+
load,
|
|
608
|
+
margin,
|
|
609
|
+
governs,
|
|
610
|
+
thickness,
|
|
611
|
+
rests,
|
|
612
|
+
findings: out,
|
|
613
|
+
};
|
|
274
614
|
}
|
|
275
615
|
/**
|
|
276
616
|
* The hole for a pin, to subtract: round standing up, a teardrop lying on its side, the diameter pinModel gives it.
|
|
277
617
|
* @param {string | Pin} p @param {object} [o] as pinModel, and at: the point on the face where the hole starts; depth:
|
|
278
|
-
* how deep (default the thickness, else the pin's length); through: out of the far face (default true where depth is
|
|
618
|
+
* how deep (default the thickness, else the pin's length); through: out of the far face (default true where depth is
|
|
619
|
+
* the thickness)
|
|
279
620
|
* @returns {object} a JSCAD geom3 with .model holding pinModel's numbers
|
|
280
621
|
*/
|
|
281
622
|
export function pinHole(p, o = {}) {
|
|
282
|
-
const what = 'pinHole',
|
|
283
|
-
|
|
623
|
+
const what = 'pinHole',
|
|
624
|
+
m = pinModel(p, optionsOf(what, o, "{ fit: 'slip', depth: 6 }")),
|
|
625
|
+
at = pointOf(what, o.at);
|
|
626
|
+
const depth = o.depth != null ? positive(what, 'depth', o.depth) : (m.thickness ?? m.length),
|
|
627
|
+
through = o.through ?? (o.depth == null && m.thickness != null);
|
|
284
628
|
if (typeof through !== 'boolean') throw new Error(`${what}: through is true or false (got ${shown(o.through)})`);
|
|
285
|
-
const h = m.hole,
|
|
629
|
+
const h = m.hole,
|
|
630
|
+
g = h.teardrop
|
|
631
|
+
? teardropHole({ d: h.diameter, length: depth, at, into: h.into, through })
|
|
632
|
+
: along(bore([[h.diameter / 2, depth]], { through }), h.into, at);
|
|
286
633
|
return Object.assign(g, { model: m });
|
|
287
634
|
}
|
|
288
635
|
|
|
289
636
|
/**
|
|
290
637
|
* A pin's solid, standing on the bed at z = 0: a snap pin as snapPin draws it from its model's figures, a plain pin a
|
|
291
638
|
* cylinder with its ends eased (a dowel's are rounded, a printed pin's chamfered against the first layer's spread).
|
|
292
|
-
* @param {string | Pin} p @param {object} [o] as pinModel @param {{ union: Function, subtract: Function }} [ops] for a
|
|
639
|
+
* @param {string | Pin} p @param {object} [o] as pinModel @param {{ union: Function, subtract: Function }} [ops] for a
|
|
640
|
+
* snap pin
|
|
293
641
|
* @returns {object} a JSCAD geom3 with .model
|
|
294
642
|
*/
|
|
295
643
|
export function pin(p, o = {}, ops) {
|
|
296
644
|
const m = pinModel(p, o);
|
|
297
|
-
if (m.snap) {
|
|
298
|
-
|
|
299
|
-
|
|
645
|
+
if (m.snap) {
|
|
646
|
+
const { lip, slot, gap, lead, back, head } = m.snap;
|
|
647
|
+
return Object.assign(snapPin({ diameter: m.diameter, length: m.length, lip, slot, gap, lead, back, head }, ops), {
|
|
648
|
+
model: m,
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
const r = m.diameter / 2,
|
|
652
|
+
c = Math.min(m.made === 'printed' ? printerOf('pin', o.printer).n('chamfer') : 0.2, r / 3, m.length / 4);
|
|
653
|
+
return Object.assign(
|
|
654
|
+
lathe(
|
|
655
|
+
[
|
|
656
|
+
[0, 0],
|
|
657
|
+
[r - c, 0],
|
|
658
|
+
[r, c],
|
|
659
|
+
[r, m.length - c],
|
|
660
|
+
[r - c, m.length],
|
|
661
|
+
[0, m.length],
|
|
662
|
+
],
|
|
663
|
+
m.made === 'printed' ? 48 : LIGHT * 2,
|
|
664
|
+
),
|
|
665
|
+
{ model: m },
|
|
666
|
+
);
|
|
300
667
|
}
|