@rulecad/fixings 0.1.4 → 0.1.6
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 +79 -0
- package/README.md +371 -7
- package/bolts.d.mts +85 -0
- package/bolts.mjs +106 -0
- package/fixings.d.mts +4 -0
- package/fixings.mjs +17 -3
- package/hardware.d.mts +8 -4
- package/hardware.mjs +15 -7
- package/magnets.d.mts +188 -0
- package/magnets.mjs +279 -0
- package/model.d.mts +4 -3
- package/model.mjs +22 -11
- package/package.json +10 -2
- package/pins.d.mts +220 -0
- package/pins.mjs +300 -0
- package/seats.mjs +2 -0
- package/snaps.d.mts +185 -0
- package/snaps.mjs +293 -0
- package/strength.d.mts +13 -0
- package/strength.mjs +17 -9
package/snaps.d.mts
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A ring load on a thin tube, as Hetényi's beam on an elastic foundation (the theory the Bayer guide's annular joint is
|
|
3
|
+
* built on): the tube's wall in ξ = βx, with β⁴ = 3 (1 − ν²) / (R² t²), bends as w'''' + 4 w = 0, and a ring load q
|
|
4
|
+
* per mm round it puts a step of q / (D β³) in w''' (D = E t³ / (12 (1 − ν²))). The load is a from one end and b from
|
|
5
|
+
* the other (each in 1/β), and each end is 'free' (no moment, no shear), 'closed' (held by an end wall: no deflection,
|
|
6
|
+
* no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load and
|
|
7
|
+
* the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w = 1/8,
|
|
8
|
+
* a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
|
|
9
|
+
* @param {number} a the load's distance from end A, in 1/β @param {number} b from end B
|
|
10
|
+
* @param {{ A?: 'free' | 'closed' | 'long', B?: 'free' | 'closed' | 'long' }} [ends] (default both long)
|
|
11
|
+
* @returns {{ w: number, bendA: number, bendB: number }}
|
|
12
|
+
*/
|
|
13
|
+
export function tubeRing(a: number, b: number, ends?: {
|
|
14
|
+
A?: "free" | "closed" | "long";
|
|
15
|
+
B?: "free" | "closed" | "long";
|
|
16
|
+
}): {
|
|
17
|
+
w: number;
|
|
18
|
+
bendA: number;
|
|
19
|
+
bendB: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number, factor: number,
|
|
23
|
+
* remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?: number, decay?: number, root?: number }} SnapPart
|
|
24
|
+
* one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
|
|
25
|
+
* "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
|
|
26
|
+
* how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
|
|
27
|
+
* (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
|
|
28
|
+
* bends, and the bending strain at the end's root
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number, length: number, undercut: number,
|
|
32
|
+
* interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material: string,
|
|
33
|
+
* lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number, insertion: number,
|
|
34
|
+
* removal: number, holds: boolean, pull: number | null, margin: number | null, most: { undercut: number, removal: number },
|
|
35
|
+
* groove: { inner: number, outer: number, depth: number }, rests: object[], findings: object[] }} AnnularSnap
|
|
36
|
+
* diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
|
|
37
|
+
* height along the axis, return face, land and lead face; undercut: the
|
|
38
|
+
* bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
|
|
39
|
+
* between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
|
|
40
|
+
* permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
|
|
41
|
+
* force it would give; groove: the groove's radii and depth in the skirt
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* An annular snap: a lid with a skirt that clicks over a bead round a round box's rim. Each part is a tube; the
|
|
45
|
+
* interference (the bead less the clearance, on the diameter) is shared between them as two springs in series, each
|
|
46
|
+
* P = y d Es X (Bayer, Snap-Fit Joints for Plastics, the annular snap joint), with Es taken as the material's modulus.
|
|
47
|
+
* The hoop strain in each is its share over its diameter, held to the plastic's limit: about 70% of its yield strain
|
|
48
|
+
* for a brief snap in an amorphous plastic, and 60% of that for a joint opened often (the same guide). Without a bead
|
|
49
|
+
* height, the bead is sized: the smallest the print can hold (fixings.snap_least), or more where pull asks it, up to
|
|
50
|
+
* what the strain allows. Refused by name: a bead no taller than the clearance (it never catches), walls that leave no
|
|
51
|
+
* tube, angles outside 0° to 90°, a lead friction locks, a groove deeper than the skirt. A closed end near the joint
|
|
52
|
+
* (the box's floor, the lid's top) is a beam on an elastic foundation held round there (Hetényi): the part is stiffer,
|
|
53
|
+
* so its mate takes more of the interference, and the bending at that end's root is held to the same limit.
|
|
54
|
+
* @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number, boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number }} p
|
|
55
|
+
* diameter: the box's wall outside, at the joint, mm; wall: the box's wall thickness there; skirt: the lid's skirt
|
|
56
|
+
* thickness; bead: how far the bead stands off the wall (default sized); lead: the face the lid pushes over, its
|
|
57
|
+
* angle from the axis (default 30); back: the return face's (default 45: the steepest the box prints without support,
|
|
58
|
+
* as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from the
|
|
59
|
+
* bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
|
|
60
|
+
* boxFloor: from the bead to the box's floor, its closed end; lidTop: from the groove to the underside of the lid's
|
|
61
|
+
* top (each default none: far enough off not to count; each at least its part's wall, the box's wall or the skirt)
|
|
62
|
+
* @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object, uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
|
|
63
|
+
* material: the box's plastic (default PLA); lidMaterial: the lid's (default the box's); printer: the printer's rule
|
|
64
|
+
* set or values (default the X1C: its fit is the clearance, its overhang the steepest return face); uses: often (the
|
|
65
|
+
* default, a lid) or once; friction: μ between the parts (default fixings.snap_friction); pull: the force along the
|
|
66
|
+
* axis the lid must stay on against, N, held to fixings.load_margin; push: the force it is pushed on with, N (warns
|
|
67
|
+
* where pushing it on square takes more)
|
|
68
|
+
* @returns {AnnularSnap}
|
|
69
|
+
*/
|
|
70
|
+
export function annularSnapModel(p: {
|
|
71
|
+
diameter: number;
|
|
72
|
+
wall: number;
|
|
73
|
+
skirt: number;
|
|
74
|
+
bead?: number;
|
|
75
|
+
lead?: number;
|
|
76
|
+
back?: number;
|
|
77
|
+
land?: number;
|
|
78
|
+
boxEnd?: number;
|
|
79
|
+
lidEnd?: number;
|
|
80
|
+
boxFloor?: number;
|
|
81
|
+
lidTop?: number;
|
|
82
|
+
}, o?: {
|
|
83
|
+
material?: string | object;
|
|
84
|
+
lidMaterial?: string | object;
|
|
85
|
+
printer?: object;
|
|
86
|
+
sets?: object;
|
|
87
|
+
uses?: "often" | "once";
|
|
88
|
+
friction?: number;
|
|
89
|
+
pull?: number;
|
|
90
|
+
push?: number;
|
|
91
|
+
}): AnnularSnap;
|
|
92
|
+
/**
|
|
93
|
+
* The bead to add to the box: a ring round the wall's outside, its foot (the bottom of the return face) at z = at.
|
|
94
|
+
* Union it with a box whose wall's outside is the model's diameter about the z axis.
|
|
95
|
+
* @param {object | AnnularSnap} p the joint's figures, as annularSnapModel takes them, or its model
|
|
96
|
+
* @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default 96)
|
|
97
|
+
* @returns {object} a JSCAD geom3 with .model
|
|
98
|
+
*/
|
|
99
|
+
export function annularBead(p: object | AnnularSnap, o?: object): object;
|
|
100
|
+
/**
|
|
101
|
+
* The groove to cut from the lid's skirt, in the same place as the bead it takes (at, as annularBead's): the bead's
|
|
102
|
+
* outline grown by the clearance all round, so the seated bead touches nothing, and with mouth, the skirt's mouth's z,
|
|
103
|
+
* a lead-in cone there at the lead angle, as wide as the bead, so the skirt's edge starts over it.
|
|
104
|
+
* @param {object | AnnularSnap} p the joint's figures or its model
|
|
105
|
+
* @param {object} [o] as annularSnapModel, and at: the bead's foot (default 0); mouth: the z of the skirt's open end,
|
|
106
|
+
* below at (default none: no lead-in); segments: faces round (default 96)
|
|
107
|
+
* @returns {object} a JSCAD geom3 to subtract, with .model
|
|
108
|
+
*/
|
|
109
|
+
export function annularGroove(p: object | AnnularSnap, o?: object): object;
|
|
110
|
+
/** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped once. */
|
|
111
|
+
export const SNAP_USES: string[];
|
|
112
|
+
export function hubFactor(k: number, nu: number): number;
|
|
113
|
+
export function shaftFactor(k: number, nu: number): number;
|
|
114
|
+
/**
|
|
115
|
+
* one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
|
|
116
|
+
* "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
|
|
117
|
+
* how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
|
|
118
|
+
* (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
|
|
119
|
+
* bends, and the bending strain at the end's root
|
|
120
|
+
*/
|
|
121
|
+
export type SnapPart = {
|
|
122
|
+
diameter: number;
|
|
123
|
+
inside: number;
|
|
124
|
+
outside: number;
|
|
125
|
+
wall: number;
|
|
126
|
+
end: number;
|
|
127
|
+
far: number;
|
|
128
|
+
factor: number;
|
|
129
|
+
remote: number;
|
|
130
|
+
X: number;
|
|
131
|
+
stiffness: number;
|
|
132
|
+
deflection: number;
|
|
133
|
+
strain: number;
|
|
134
|
+
closed: number | null;
|
|
135
|
+
stiffer?: number;
|
|
136
|
+
decay?: number;
|
|
137
|
+
root?: number;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
|
|
141
|
+
* height along the axis, return face, land and lead face; undercut: the
|
|
142
|
+
* bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
|
|
143
|
+
* between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
|
|
144
|
+
* permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
|
|
145
|
+
* force it would give; groove: the groove's radii and depth in the skirt
|
|
146
|
+
*/
|
|
147
|
+
export type AnnularSnap = {
|
|
148
|
+
kind: "annular snap";
|
|
149
|
+
diameter: number;
|
|
150
|
+
wall: number;
|
|
151
|
+
skirt: number;
|
|
152
|
+
clearance: number;
|
|
153
|
+
bead: number;
|
|
154
|
+
length: number;
|
|
155
|
+
undercut: number;
|
|
156
|
+
interference: number;
|
|
157
|
+
lead: number;
|
|
158
|
+
back: number;
|
|
159
|
+
land: number;
|
|
160
|
+
sized: boolean;
|
|
161
|
+
uses: "often" | "once";
|
|
162
|
+
material: string;
|
|
163
|
+
lidMaterial: string;
|
|
164
|
+
friction: number;
|
|
165
|
+
permissible: number;
|
|
166
|
+
box: SnapPart;
|
|
167
|
+
lid: SnapPart;
|
|
168
|
+
force: number;
|
|
169
|
+
insertion: number;
|
|
170
|
+
removal: number;
|
|
171
|
+
holds: boolean;
|
|
172
|
+
pull: number | null;
|
|
173
|
+
margin: number | null;
|
|
174
|
+
most: {
|
|
175
|
+
undercut: number;
|
|
176
|
+
removal: number;
|
|
177
|
+
};
|
|
178
|
+
groove: {
|
|
179
|
+
inner: number;
|
|
180
|
+
outer: number;
|
|
181
|
+
depth: number;
|
|
182
|
+
};
|
|
183
|
+
rests: object[];
|
|
184
|
+
findings: object[];
|
|
185
|
+
};
|
package/snaps.mjs
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Annular snaps: a lid that clicks on. A bead runs round the outside of a round box's wall near its rim; the lid's
|
|
2
|
+
// skirt has a groove inside it the bead's shape plus a clearance. Pushed on, the bead's lead face spreads the skirt and
|
|
3
|
+
// squeezes the box's wall; past it, both spring back and the bead sits in the groove with no stress left in either.
|
|
4
|
+
// Pulled, the bead's return face has to spread the skirt again. annularSnapModel gives the forces and the hoop strain in
|
|
5
|
+
// each part from the Bayer snap-fit design guide's annular joint (a beam on an elastic foundation: P = y d Es X, with
|
|
6
|
+
// X from the tube's proportions), the two parts as springs in series where both give, and the strain held to the
|
|
7
|
+
// plastic's limit by the guide's rule for a brief snap. annularBead is the bead to add to the box's wall, annularGroove
|
|
8
|
+
// the groove (and the skirt's lead-in) to cut from the lid. Units: mm, N, MPa, degrees.
|
|
9
|
+
import { DEFAULTS, printerOf, rest, finding, positive, oneOf, isNum, shown, mm, r3 } from './model.mjs';
|
|
10
|
+
import { lathe } from './draw.mjs';
|
|
11
|
+
import { optionsOf } from './holes.mjs';
|
|
12
|
+
import { materialOf } from './strength.mjs';
|
|
13
|
+
|
|
14
|
+
const n1 = (x) => +x.toFixed(1), n2 = (x) => +x.toFixed(2), n4 = (x) => +x.toFixed(4), pc = (x) => `${mm(n2(x * 100))}%`;
|
|
15
|
+
const tan = (deg) => Math.tan((deg * Math.PI) / 180);
|
|
16
|
+
/** The uses an annular snap is sized for: opened often (a lid, the guide's 60% of the brief-snap strain) or snapped once. */
|
|
17
|
+
export const SNAP_USES = ['often', 'once'];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The geometric factor of the Bayer guide's annular snap joint for the outer part, a tube (the hub, here the lid's
|
|
21
|
+
* skirt) spread over a rigid shaft: X_N = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) + ν), k = d0 / d.
|
|
22
|
+
* @param {number} k the tube's outside diameter over its inside diameter at the joint @param {number} nu Poisson's ratio
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
export const hubFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) + nu);
|
|
26
|
+
/**
|
|
27
|
+
* The same for the inner part, a hollow shaft (here the box's wall) squeezed in a rigid tube:
|
|
28
|
+
* X_W = 0.62 √((k − 1)/(k + 1)) / ((k² + 1)/(k² − 1) − ν), k = d / di.
|
|
29
|
+
* @param {number} k the shaft's outside diameter at the joint over its inside diameter @param {number} nu Poisson's ratio
|
|
30
|
+
* @returns {number}
|
|
31
|
+
*/
|
|
32
|
+
export const shaftFactor = (k, nu) => (0.62 * Math.sqrt((k - 1) / (k + 1))) / ((k * k + 1) / (k * k - 1) - nu);
|
|
33
|
+
|
|
34
|
+
// The force along the push to make a transverse force P over a face at deg from the axis, with friction mu: the
|
|
35
|
+
// guide's W = P (μ + tan α) / (1 − μ tan α). A square face, or one friction locks, never lets go
|
|
36
|
+
const along = (P, deg, mu) => (deg >= 90 || mu * tan(deg) >= 1 ? Infinity : (P * (mu + tan(deg))) / (1 - mu * tan(deg)));
|
|
37
|
+
const per = (deg, mu) => along(1, deg, mu);
|
|
38
|
+
// How much stiffer a joint is for lying away from its tube's free end: 1 at the end, the guide's 3 once it is at least
|
|
39
|
+
// 1.8 √(d t) in, and straight between (the guide gives only the ends; the line between is an estimate)
|
|
40
|
+
const remote = (end, d, t) => { const far = 1.8 * Math.sqrt(d * t), k = DEFAULTS.snap_remote.value; return { far: n2(far), factor: 1 + (k - 1) * Math.min(1, end / far) }; };
|
|
41
|
+
|
|
42
|
+
// e^(s u) (A cos u + B sin u) and its n-th derivative in u, at u
|
|
43
|
+
const wave = (s, A, B, u, n) => { for (let i = 0; i < n; i++) [A, B] = [s * A + B, s * B - A]; return Math.exp(s * u) * (A * Math.cos(u) + B * Math.sin(u)); };
|
|
44
|
+
const LONG = 12; // a tube this many 1/β long is long: e^-12 of the load is left at its far end
|
|
45
|
+
/**
|
|
46
|
+
* A ring load on a thin tube, as Hetényi's beam on an elastic foundation (the theory the Bayer guide's annular joint is
|
|
47
|
+
* built on): the tube's wall in ξ = βx, with β⁴ = 3 (1 − ν²) / (R² t²), bends as w'''' + 4 w = 0, and a ring load q
|
|
48
|
+
* per mm round it puts a step of q / (D β³) in w''' (D = E t³ / (12 (1 − ν²))). The load is a from one end and b from
|
|
49
|
+
* the other (each in 1/β), and each end is 'free' (no moment, no shear), 'closed' (held by an end wall: no deflection,
|
|
50
|
+
* no slope, the stiffest an end can be) or 'long' (far enough off not to count). Gives the deflection under the load and
|
|
51
|
+
* the curvature w'' at each end, both per q / (D β³). The free-standing checks: a long tube both ways gives w = 1/8,
|
|
52
|
+
* a free end at the load gives 1/2 (Hetényi, Beams on Elastic Foundation, 1946: w = Pβ / 2k and 2Pβ / k).
|
|
53
|
+
* @param {number} a the load's distance from end A, in 1/β @param {number} b from end B
|
|
54
|
+
* @param {{ A?: 'free' | 'closed' | 'long', B?: 'free' | 'closed' | 'long' }} [ends] (default both long)
|
|
55
|
+
* @returns {{ w: number, bendA: number, bendB: number }}
|
|
56
|
+
*/
|
|
57
|
+
export function tubeRing(a, b, ends = {}) {
|
|
58
|
+
const what = 'tubeRing', kinds = ['free', 'closed', 'long'];
|
|
59
|
+
for (const [k, v] of [['a', a], ['b', b]]) if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is the load's distance from an end, in 1/β, 0 or more (got ${shown(v)})`);
|
|
60
|
+
if (ends == null || typeof ends !== 'object' || Array.isArray(ends)) throw new Error(`${what}: ends is { A, B }, each free, closed or long (got ${shown(ends)})`);
|
|
61
|
+
// An end more than twice LONG away is long whatever it is: e^-24 of the load reaches it, and its e^u waves would
|
|
62
|
+
// overflow a double past about 709/β (its curvature there is then 0 to that precision)
|
|
63
|
+
const A0 = oneOf(what, 'ends.A', ends.A ?? 'long', kinds), B0 = oneOf(what, 'ends.B', ends.B ?? 'long', kinds);
|
|
64
|
+
const A = a > 2 * LONG ? 'long' : A0, B = b > 2 * LONG ? 'long' : B0, la = A === 'long' ? LONG : a, lb = B === 'long' ? LONG : b;
|
|
65
|
+
// Each side of the load has its own four waves, from its start: e^-u cos u, e^-u sin u, e^u cos u, e^u sin u
|
|
66
|
+
const row = (side, u, n, sign = 1) => { const r = Array(8).fill(0); [[-1, 1, 0], [-1, 0, 1], [1, 1, 0], [1, 0, 1]].forEach(([s, c, si], i) => { r[side * 4 + i] = sign * wave(s, c, si, u, n); }); return r; };
|
|
67
|
+
const end = (side, u, kind) => (kind === 'closed' ? [0, 1] : [2, 3]).map((n) => [row(side, u, n), 0]);
|
|
68
|
+
const eqs = [...end(0, 0, A), ...end(1, lb, B)];
|
|
69
|
+
for (const n of [0, 1, 2, 3]) { const l = row(0, la, n, -1), r = row(1, 0, n); eqs.push([l.map((x, i) => x + r[i]), n === 3 ? 1 : 0]); }
|
|
70
|
+
// Gauss with partial pivoting
|
|
71
|
+
const M = eqs.map(([r, v]) => [...r, v]);
|
|
72
|
+
for (let c = 0; c < 8; c++) {
|
|
73
|
+
let p = c; for (let r = c + 1; r < 8; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
|
|
74
|
+
[M[c], M[p]] = [M[p], M[c]];
|
|
75
|
+
for (let r = 0; r < 8; r++) if (r !== c) { const k = M[r][c] / M[c][c]; for (let j = c; j < 9; j++) M[r][j] -= k * M[c][j]; }
|
|
76
|
+
}
|
|
77
|
+
const x = M.map((r, i) => r[8] / r[i]), at = (side, u, n) => row(side, u, n).reduce((t, v, i) => t + v * x[i], 0);
|
|
78
|
+
return { w: at(1, 0, 0), bendA: A === A0 ? at(0, 0, 2) : 0, bendB: B === B0 ? at(1, lb, 2) : 0 };
|
|
79
|
+
}
|
|
80
|
+
// A closed end near the joint: how much stiffer it makes the part (the beam's deflection with the end open over that
|
|
81
|
+
// with it closed, the rest of the tube as it is) and the bending strain at the closed end's root per N of P
|
|
82
|
+
const closedEnd = (free, shut, Rm, t, d, E, nu) => {
|
|
83
|
+
const beta = Math.pow((3 * (1 - nu * nu)) / (Rm * Rm * t * t), 0.25), a = free * beta, b = shut * beta;
|
|
84
|
+
const open = tubeRing(a, LONG, { A: 'free' }), closed = tubeRing(a, b, { A: 'free', B: 'closed' });
|
|
85
|
+
// q = P / (π d) per mm round; M = D w''(x) = w''(ξ) q / β; the strain at the face is 6 M (1 − ν²) / (E t²)
|
|
86
|
+
const perP = (6 * Math.abs(closed.bendB) * (1 - nu * nu)) / (Math.PI * d * beta * E * t * t);
|
|
87
|
+
return { beta, stiffer: open.w / closed.w, perP };
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* @typedef {{ diameter: number, inside: number, outside: number, wall: number, end: number, far: number, factor: number,
|
|
92
|
+
* remote: number, X: number, stiffness: number, deflection: number, strain: number, closed: number | null, stiffer?: number, decay?: number, root?: number }} SnapPart
|
|
93
|
+
* one part of the joint: its diameters at the joint, wall, how far the joint is from its free end and the guide's
|
|
94
|
+
* "remote" distance, the stiffening that gives (remote), and with a closed end's too (factor), the geometric factor, its stiffness (N per mm of diameter),
|
|
95
|
+
* how much of the interference it takes (on the diameter) and the hoop strain that leaves in it; with a closed end
|
|
96
|
+
* (closed, its distance from the joint), how much stiffer that end makes it, the length 1/β over which its wall
|
|
97
|
+
* bends, and the bending strain at the end's root
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* @typedef {{ kind: 'annular snap', diameter: number, wall: number, skirt: number, clearance: number, bead: number, length: number, undercut: number,
|
|
101
|
+
* interference: number, lead: number, back: number, land: number, sized: boolean, uses: 'often' | 'once', material: string,
|
|
102
|
+
* lidMaterial: string, friction: number, permissible: number, box: SnapPart, lid: SnapPart, force: number, insertion: number,
|
|
103
|
+
* removal: number, holds: boolean, pull: number | null, margin: number | null, most: { undercut: number, removal: number },
|
|
104
|
+
* groove: { inner: number, outer: number, depth: number }, rests: object[], findings: object[] }} AnnularSnap
|
|
105
|
+
* diameter: the box's wall outside at the joint; bead: how far the bead stands off it (radial); length: the bead's
|
|
106
|
+
* height along the axis, return face, land and lead face; undercut: the
|
|
107
|
+
* bead less the clearance, the radial overlap the skirt is spread by; interference: the same on the diameter, shared
|
|
108
|
+
* between the parts; force: the transverse force P that takes; insertion and removal: along the push, N;
|
|
109
|
+
* permissible: the hoop strain each part may see; most: the largest undercut that strain allows and the removal
|
|
110
|
+
* force it would give; groove: the groove's radii and depth in the skirt
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* An annular snap: a lid with a skirt that clicks over a bead round a round box's rim. Each part is a tube; the
|
|
115
|
+
* interference (the bead less the clearance, on the diameter) is shared between them as two springs in series, each
|
|
116
|
+
* P = y d Es X (Bayer, Snap-Fit Joints for Plastics, the annular snap joint), with Es taken as the material's modulus.
|
|
117
|
+
* The hoop strain in each is its share over its diameter, held to the plastic's limit: about 70% of its yield strain
|
|
118
|
+
* for a brief snap in an amorphous plastic, and 60% of that for a joint opened often (the same guide). Without a bead
|
|
119
|
+
* height, the bead is sized: the smallest the print can hold (fixings.snap_least), or more where pull asks it, up to
|
|
120
|
+
* what the strain allows. Refused by name: a bead no taller than the clearance (it never catches), walls that leave no
|
|
121
|
+
* tube, angles outside 0° to 90°, a lead friction locks, a groove deeper than the skirt. A closed end near the joint
|
|
122
|
+
* (the box's floor, the lid's top) is a beam on an elastic foundation held round there (Hetényi): the part is stiffer,
|
|
123
|
+
* so its mate takes more of the interference, and the bending at that end's root is held to the same limit.
|
|
124
|
+
* @param {{ diameter: number, wall: number, skirt: number, bead?: number, lead?: number, back?: number, land?: number, boxEnd?: number, lidEnd?: number, boxFloor?: number, lidTop?: number }} p
|
|
125
|
+
* diameter: the box's wall outside, at the joint, mm; wall: the box's wall thickness there; skirt: the lid's skirt
|
|
126
|
+
* thickness; bead: how far the bead stands off the wall (default sized); lead: the face the lid pushes over, its
|
|
127
|
+
* angle from the axis (default 30); back: the return face's (default 45: the steepest the box prints without support,
|
|
128
|
+
* as it is the underside of the bead); land: the bead's flat top, along the axis (default two layers); boxEnd: from the
|
|
129
|
+
* bead to the box's rim, its free end; lidEnd: from the groove to the skirt's mouth (each default 0, at the end);
|
|
130
|
+
* boxFloor: from the bead to the box's floor, its closed end; lidTop: from the groove to the underside of the lid's
|
|
131
|
+
* top (each default none: far enough off not to count; each at least its part's wall, the box's wall or the skirt)
|
|
132
|
+
* @param {{ material?: string | object, lidMaterial?: string | object, printer?: object, sets?: object, uses?: 'often' | 'once', friction?: number, pull?: number, push?: number }} [o]
|
|
133
|
+
* material: the box's plastic (default PLA); lidMaterial: the lid's (default the box's); printer: the printer's rule
|
|
134
|
+
* set or values (default the X1C: its fit is the clearance, its overhang the steepest return face); uses: often (the
|
|
135
|
+
* default, a lid) or once; friction: μ between the parts (default fixings.snap_friction); pull: the force along the
|
|
136
|
+
* axis the lid must stay on against, N, held to fixings.load_margin; push: the force it is pushed on with, N (warns
|
|
137
|
+
* where pushing it on square takes more)
|
|
138
|
+
* @returns {AnnularSnap}
|
|
139
|
+
*/
|
|
140
|
+
export function annularSnapModel(p, o = {}) {
|
|
141
|
+
const what = 'annularSnapModel';
|
|
142
|
+
if (p == null || typeof p !== 'object' || Array.isArray(p)) throw new Error(`${what}: give the joint's figures ({ diameter: 60, wall: 1.68, skirt: 1.26 }), not ${shown(p)}`);
|
|
143
|
+
optionsOf(what, o, '{ material: \'pla\', pull: 10 }');
|
|
144
|
+
const d = positive(what, 'diameter', p.diameter), t = positive(what, 'wall', p.wall), s = positive(what, 'skirt', p.skirt);
|
|
145
|
+
if (t >= d / 2) throw new Error(`${what}: a wall of ${mm(t)} mm fills a ${mm(d)} mm box: the box's wall is under half its diameter, so it is a tube that gives`);
|
|
146
|
+
const pr = printerOf(what, o.printer), c = pr.n('fit'), layer = pr.n('layer'), overhang = pr.n('overhang');
|
|
147
|
+
const angle = (k, v, dflt) => { const x = v ?? dflt; if (!(isNum(x) && x > 0 && x <= 90)) throw new Error(`${what}: ${k} is an angle from the axis above 0° and at most 90°, in degrees (got ${shown(v)})`); return x; };
|
|
148
|
+
const lead = angle('lead', p.lead, 30), back = angle('back', p.back, 45);
|
|
149
|
+
if (lead >= 90) throw new Error(`${what}: a lead of 90° is a square face the lid cannot be pushed over: give a lead under 90°, 30° to 45° is usual`);
|
|
150
|
+
const land = p.land != null ? positive(what, 'land', p.land) : r3(2 * layer);
|
|
151
|
+
const end = (k) => { const v = p[k] ?? 0; if (!(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is how far the joint is from that part's free end, 0 mm or more (got ${shown(p[k])})`); return v; };
|
|
152
|
+
// A closed end at the joint itself (0 mm) holds the wall rigid there, so it cannot give at all; one nearer than the
|
|
153
|
+
// wall is thick is a solid corner, not a tube's wall that bends, which the beam on an elastic foundation (a thin-shell
|
|
154
|
+
// theory) does not model, and its sums lose their sign to rounding as the distance goes to 0. Both refused
|
|
155
|
+
const shut = (k, what2, wall, wallName) => { if (p[k] == null) return null; const v = p[k]; if (!(isNum(v) && v >= wall - 1e-9)) throw new Error(`${what}: ${k} is how far the joint is from ${what2}, its closed end, at least the ${mm(wall)} mm ${wallName} (got ${shown(v)}): a joint nearer its closed end than that is a solid corner that cannot give, so move it further off`); return v; };
|
|
156
|
+
const boxFloor = shut('boxFloor', 'the box\'s floor', t, 'wall'), lidTop = shut('lidTop', 'the lid\'s top', s, 'skirt');
|
|
157
|
+
const boxEnd = end('boxEnd'), lidEnd = end('lidEnd'), uses = oneOf(what, 'uses', o.uses ?? 'often', SNAP_USES);
|
|
158
|
+
const mu = o.friction ?? DEFAULTS.snap_friction.value;
|
|
159
|
+
if (!(isNum(mu) && mu >= 0 && mu < 1)) throw new Error(`${what}: friction is μ between the parts, 0 or more and under 1 (got ${shown(o.friction)})`);
|
|
160
|
+
if (mu * tan(lead) >= 1 - 1e-9) throw new Error(`${what}: a ${mm(lead)}° lead at friction ${mm(mu)} locks: μ tan α is ${mm(n2(mu * tan(lead)))}, 1 or more, so no push slides the skirt over it. Give a lead under ${mm(n1((Math.atan(1 / mu) * 180) / Math.PI))}° at that friction, 30° to 45° is usual`);
|
|
161
|
+
const pull = o.pull != null ? positive(what, 'pull (along the axis, in N)', o.pull) : null, push = o.push != null ? positive(what, 'push (along the axis, in N)', o.push) : null;
|
|
162
|
+
if (p.bead != null && !(isNum(p.bead) && p.bead > c + 1e-9)) throw new Error(`${what}: a bead of ${shown(p.bead)} mm is no taller than the ${pr.cite('fit')} clearance of ${mm(c)} mm round the skirt, so it never catches: give a bead over ${mm(c)} mm, or leave it out to have it sized`);
|
|
163
|
+
if (p.bead != null && p.bead >= s - 1e-9) throw new Error(`${what}: a bead of ${mm(p.bead)} mm needs a groove as deep in the ${mm(s)} mm skirt, which cuts right through it: give a skirt thicker than the bead, by a print line or more`);
|
|
164
|
+
const box = materialOf(what, o.material ?? 'pla', o.sets), lidMat = materialOf(what, o.lidMaterial ?? o.material ?? 'pla', o.sets);
|
|
165
|
+
for (const m of [box, lidMat]) if (!m.poisson) throw new Error(`${what}: ${m.name} has no poisson in its rule set, which the guide's geometric factor needs`);
|
|
166
|
+
if (box.cls !== 'plastic' || lidMat.cls !== 'plastic') throw new Error(`${what}: an annular snap is two printed plastic parts; ${box.cls !== 'plastic' ? box.name : lidMat.name} is a ${box.cls !== 'plastic' ? box.cls : lidMat.cls}`);
|
|
167
|
+
|
|
168
|
+
// The permissible hoop strain: the guide's share of the yield strain, the yield strain taken as strength over modulus
|
|
169
|
+
// (a straight line to the strength, so below the real yield strain: on the safe side), and 60% of that if opened often
|
|
170
|
+
const brief = DEFAULTS.snap_brief.value, often = uses === 'often' ? DEFAULTS.snap_often.value : 1;
|
|
171
|
+
const limitOf = (m) => (brief * often * m.strength.value) / m.modulus.value, permissible = Math.min(limitOf(box), limitOf(lidMat));
|
|
172
|
+
|
|
173
|
+
// Each part as a spring on the diameter: P = y d Es X, stiffened where the joint lies away from its free end
|
|
174
|
+
const di = d - 2 * t, dh = d + 2 * c, d0 = dh + 2 * s;
|
|
175
|
+
// A closed end (the box's floor, the lid's top) near the joint holds the tube round there: Hetényi's beam on an elastic
|
|
176
|
+
// foundation gives how much stiffer that makes it than the same tube open, and the bending at the closed end's root
|
|
177
|
+
const part = (diameter, inside, outside, wall, endAt, closedAt, X, m) => {
|
|
178
|
+
const r = remote(endAt, diameter, wall), E = m.modulus.value, nu = m.poisson.value;
|
|
179
|
+
const ce = closedAt == null ? null : closedEnd(endAt, closedAt, (inside + outside) / 4, wall, diameter, E, nu), factor = r.factor * (ce ? ce.stiffer : 1);
|
|
180
|
+
return { diameter: r3(diameter), inside: r3(inside), outside: r3(outside), wall, end: endAt, far: r.far, remote: n2(r.factor), factor: n2(factor), X, stiffness: factor * diameter * E * X,
|
|
181
|
+
closed: closedAt, ...(ce ? { stiffer: n2(ce.stiffer), decay: n2(1 / ce.beta), rootPerP: ce.perP } : {}) };
|
|
182
|
+
};
|
|
183
|
+
const B = part(d, di, d, t, boxEnd, boxFloor, shaftFactor(d / di, box.poisson.value), box), L = part(dh, dh, d0, s, lidEnd, lidTop, hubFactor(d0 / dh, lidMat.poisson.value), lidMat);
|
|
184
|
+
const k = 1 / (1 / B.stiffness + 1 / L.stiffness);
|
|
185
|
+
// The most force (and so interference) the strain allows: P = ε k_i d_i in each part
|
|
186
|
+
// The most force (and so interference) the strain allows: P = ε k_i d_i in each part, and at a closed end's root P = ε / (strain per N)
|
|
187
|
+
const Pmost = Math.min(permissible * B.stiffness * B.diameter, permissible * L.stiffness * L.diameter, ...[B, L].filter((q) => q.rootPerP).map((q) => permissible / q.rootPerP)), mostUndercut = Pmost / k / 2;
|
|
188
|
+
// to the thousandth: the sized bead is rounded up to what the pull needs and down to what the strain allows
|
|
189
|
+
const up = (x) => Math.ceil(x * 1000 - 1e-6) / 1000, down = (x) => Math.floor(x * 1000 + 1e-6) / 1000;
|
|
190
|
+
const least = DEFAULTS.snap_least.value, back1 = per(back, mu), want = DEFAULTS.load_margin.value;
|
|
191
|
+
let undercut, sized = false, sizeSays = null;
|
|
192
|
+
if (p.bead != null) undercut = p.bead - c;
|
|
193
|
+
else {
|
|
194
|
+
sized = true;
|
|
195
|
+
const need = pull != null && Number.isFinite(back1) ? (want * pull) / back1 / k / 2 : 0;
|
|
196
|
+
undercut = Math.max(least, up(need));
|
|
197
|
+
sizeSays = need > least ? `sized from the ${mm(pull)} N pull: ${mm(want)} times it over the ${mm(back)}° return face` : `sized as the smallest the print holds, fixings.snap_least ${mm(least)} mm${pull != null ? `, which already holds the ${mm(pull)} N pull ${mm(want)} times over` : ''}`;
|
|
198
|
+
if (undercut > mostUndercut) { sizeSays += `, more than the ${mm(r3(mostUndercut))} mm the strain allows, so held to that`; undercut = Math.max(down(mostUndercut), 0); }
|
|
199
|
+
undercut = r3(undercut);
|
|
200
|
+
}
|
|
201
|
+
const bead = r3(undercut + c), Y = 2 * undercut, P = k * Y, length = r3(bead / tan(back) + land + bead / tan(lead));
|
|
202
|
+
// The strains are judged unrounded (exact, below), and shown to 4 places: a bead held to the strain's limit could round over it
|
|
203
|
+
const exact = new Map();
|
|
204
|
+
for (const q of [B, L]) { const e = { strain: P / q.stiffness / q.diameter, root: q.rootPerP != null ? P * q.rootPerP : null }; exact.set(q, e);
|
|
205
|
+
q.deflection = r3(P / q.stiffness); q.strain = n4(e.strain); if (q.rootPerP != null) { q.root = n4(e.root); delete q.rootPerP; } q.X = +q.X.toPrecision(3); q.stiffness = n1(q.stiffness); }
|
|
206
|
+
const insertion = along(P, lead, mu), removal = along(P, back, mu), holds = !Number.isFinite(removal), most = { undercut: down(mostUndercut), removal: Number.isFinite(back1) ? n1(back1 * Pmost) : Infinity };
|
|
207
|
+
|
|
208
|
+
const out = [], rests = [], cited = (m) => `${m.strength.name} ${mm(m.strength.value)} MPa over ${m.modulus.name} ${mm(m.modulus.value)} MPa`;
|
|
209
|
+
rests.push(pr.rest('fit'), pr.rest('overhang'), rest(box.modulus.name, box.modulus), rest(box.strength.name, box.strength), rest(box.poisson.name, box.poisson),
|
|
210
|
+
rest('fixings.snap_brief', DEFAULTS.snap_brief), ...(uses === 'often' ? [rest('fixings.snap_often', DEFAULTS.snap_often)] : []), rest('fixings.snap_remote', DEFAULTS.snap_remote), pr.rest('line'));
|
|
211
|
+
if (lidMat !== box && lidMat.name !== box.name) rests.push(rest(lidMat.modulus.name, lidMat.modulus), rest(lidMat.strength.name, lidMat.strength), rest(lidMat.poisson.name, lidMat.poisson));
|
|
212
|
+
if (o.friction == null) rests.push(rest('fixings.snap_friction', DEFAULTS.snap_friction));
|
|
213
|
+
if (sized) rests.push(rest('fixings.snap_least', DEFAULTS.snap_least));
|
|
214
|
+
if (pull != null) rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
|
|
215
|
+
out.push(finding('info', `a ${mm(bead)} mm bead round the ${mm(d)} mm box, in a skirt ${mm(c)} mm clear of the wall (${pr.cite('fit')}): ${mm(undercut)} mm of undercut, ${mm(r3(Y))} mm on the diameter, shared by the box's wall (${mm(B.deflection)} mm) and the lid's skirt (${mm(L.deflection)} mm)${sized ? `, ${sizeSays}` : ''}`,
|
|
216
|
+
'snap.undercut', { values: { bead, undercut, interference: r3(Y), box: B.deflection, lid: L.deflection } }));
|
|
217
|
+
for (const [q, name, m] of [[B, 'the box\'s wall', box], [L, 'the lid\'s skirt', lidMat]]) {
|
|
218
|
+
const ok = exact.get(q).strain <= permissible * (1 + 1e-9);
|
|
219
|
+
out.push(finding(ok ? 'pass' : 'fail', `${name} is ${ok ? '' : 'over its limit: '}${pc(q.strain)} hoop strain (${mm(q.deflection)} mm over ${mm(q.diameter)} mm) where ${m.name} may see ${pc(permissible)}: ${mm(DEFAULTS.snap_brief.value)} of its yield strain, ${cited(m)}${uses === 'often' ? `, and ${mm(DEFAULTS.snap_often.value)} of that since it is opened often` : ''}${ok ? '' : `. The most undercut the strain allows is ${mm(most.undercut)} mm: a smaller bead, a thinner ${q === B ? 'wall' : 'skirt'}, or a bigger box`}`,
|
|
220
|
+
'snap.strain', { values: { strain: q.strain, permissible: n4(permissible), deflection: q.deflection, diameter: q.diameter }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
|
|
221
|
+
}
|
|
222
|
+
for (const [q, name, m, endName] of [[B, 'the box\'s wall', box, 'floor'], [L, 'the lid\'s skirt', lidMat, 'top']]) {
|
|
223
|
+
if (q.closed == null) continue;
|
|
224
|
+
out.push(finding('info', `${name} meets its ${endName} ${mm(n2(q.closed))} mm from the joint, where a tube's wall bends over about 1/β = ${mm(q.decay)} mm: ${q.stiffer >= 1.01 ? `held round there, it is ${mm(q.stiffer)} times as stiff as the same tube open` : 'far enough off to make no difference to its stiffness'} (Hetényi's beam on an elastic foundation, the ${endName} taken as fully closed, the stiffest it can be)`,
|
|
225
|
+
'snap.closed', { values: { closed: q.closed, decay: q.decay, stiffer: q.stiffer }, refs: { part: q === B ? 'box' : 'lid' } }));
|
|
226
|
+
const ok = exact.get(q).root <= permissible * (1 + 1e-9);
|
|
227
|
+
out.push(finding(ok ? 'pass' : 'fail', `${name} bends where it meets its ${endName}: ${pc(q.root)} strain at the root where ${m.name} may see ${pc(permissible)}${ok ? '' : `. Move the joint further from the ${endName} (the wall bends over about 1/β, ${mm(q.decay)} mm), or a smaller bead: the most undercut the strain allows is ${mm(most.undercut)} mm`}`,
|
|
228
|
+
'snap.root', { values: { strain: q.root, permissible: n4(permissible), closed: q.closed }, refs: { part: q === B ? 'box' : 'lid', material: m.name } }));
|
|
229
|
+
}
|
|
230
|
+
// The groove is cut the bead's depth into the skirt: what is left behind it must print as a wall of at least one line
|
|
231
|
+
const line = pr.n('line'), left = r3(s - bead), thick = left >= line - 1e-9;
|
|
232
|
+
out.push(finding(thick ? 'pass' : 'fail', `the groove leaves ${mm(left)} mm of the ${mm(s)} mm skirt behind it${thick ? `, at least the ${pr.cite('line')} ${mm(line)} mm line` : `, under the ${pr.cite('line')} ${mm(line)} mm line, so it prints thin or not at all: a thicker skirt, or a smaller bead`}`,
|
|
233
|
+
'snap.skirt', { values: { left, skirt: s, line } }));
|
|
234
|
+
if (undercut < least - 1e-9) out.push(finding('warn', `an undercut of ${mm(undercut)} mm is under fixings.snap_least, ${mm(least)} mm: the print's own error is that size, so the lid may not catch, or catch only in places`, 'snap.least', { values: { undercut, least } }));
|
|
235
|
+
out.push(finding('info', `${mm(n1(insertion))} N to push the lid on square and ${holds ? 'it holds for good (a square return face)' : `${mm(n1(removal))} N to pull it off square`}: a transverse force of ${mm(n1(P))} N (P = y d Es X, Bayer's annular snap joint, X ${mm(B.X)} for the wall and ${mm(L.X)} for the skirt) through the ${mm(lead)}° lead and ${mm(back)}° return faces at μ ${mm(mu)}. Pressed on at a tilt, a part of the bead at a time, it takes much less, as the guide says of a lid put on by hand`,
|
|
236
|
+
'snap.forces', { values: { force: n1(P), insertion: n1(insertion), removal: Number.isFinite(removal) ? n1(removal) : null, friction: mu } }));
|
|
237
|
+
if (B.remote > 1 || L.remote > 1) out.push(finding('info', `the joint lies in from a free end (box ${mm(boxEnd)} mm of ${mm(B.far)}, lid ${mm(lidEnd)} mm of ${mm(L.far)}, where 1.8 √(d t) counts as remote), so it is stiffer by ${mm(B.remote)} and ${mm(L.remote)} times: the guide gives 3 at a remote joint, and the line between is an estimate`, 'snap.remote', { values: { box: B.remote, lid: L.remote } }));
|
|
238
|
+
if (push != null) { const ok = insertion <= push; out.push(finding(ok ? 'pass' : 'warn', `pushed with ${mm(push)} N, the lid goes on ${ok ? `square, ${mm(n1(insertion))} N` : `only at a tilt: square it takes ${mm(n1(insertion))} N. A shallower lead or a smaller bead lowers it`}`, 'snap.push', { values: { push, insertion: n1(insertion) } })); }
|
|
239
|
+
const margin = pull != null ? (holds ? Infinity : n2(removal / pull)) : null;
|
|
240
|
+
if (pull != null) out.push(finding(margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail', `pulled with ${mm(pull)} N, the lid stays on ${holds ? 'for good' : `${mm(margin)} times over (${mm(n1(removal))} N)`}${margin >= want ? '' : margin >= 1 ? `, under the ${mm(want)} times fixings.load_margin asks` : ': it comes off'}${margin >= want ? '' : `. The strain allows up to ${mm(most.undercut)} mm of undercut, which would hold ${mm(most.removal)} N`}`,
|
|
241
|
+
'snap.hold', { values: { pull, removal: Number.isFinite(removal) ? n1(removal) : null, margin: Number.isFinite(margin) ? margin : null, want } }));
|
|
242
|
+
else out.push(finding('info', `give pull, the force the lid must stay on against, to have its hold checked`, 'snap.hold'));
|
|
243
|
+
// Printing: the box stands on its floor, so the bead's return face is an overhang; the lid is printed on its top, so
|
|
244
|
+
// the groove's face nearest the mouth, the return face's mate, is a ceiling at the same angle. The lead face and the
|
|
245
|
+
// skirt's lead-in lean the other way and always print
|
|
246
|
+
const prints = back <= overhang + 1e-9;
|
|
247
|
+
out.push(finding(prints ? 'pass' : 'fail', prints ? `the box printed standing on its floor and the lid on its top print with no support: the bead's ${mm(back)}° return face and the groove's mating face are within ${pr.cite('overhang')} ${mm(overhang)}°, and the ${mm(lead)}° lead face leans the way that always prints`
|
|
248
|
+
: `the ${mm(back)}° return face is past ${pr.cite('overhang')} ${mm(overhang)}°: under the box's bead and over the lid's groove it needs support. Give back ${mm(overhang)}° or less; a steeper face holds harder, so let the bead be taller instead`, 'snap.printable', { values: { back, overhang } }));
|
|
249
|
+
const groove = { inner: r3(dh / 2), outer: r3(dh / 2 + bead), depth: bead };
|
|
250
|
+
return { kind: 'annular snap', diameter: d, wall: t, skirt: s, clearance: c, bead, length, undercut, interference: r3(Y), lead, back, land, sized, uses, material: box.name, lidMaterial: lidMat.name, friction: mu,
|
|
251
|
+
permissible: n4(permissible), box: B, lid: L, force: n1(P), insertion: Number.isFinite(insertion) ? n1(insertion) : Infinity, removal: Number.isFinite(removal) ? n1(removal) : Infinity, holds, pull, margin, most, groove, rests, findings: out };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// The bead's outline in [radius, z] from its foot on the wall at z: up the return face, along the land, down the lead
|
|
255
|
+
// face, sunk into the wall by a little so it joins it
|
|
256
|
+
const beadOutline = (m, z, grow = 0) => {
|
|
257
|
+
const R = m.diameter / 2 + grow, h = m.bead, rise = h / tan(m.back), fall = h / tan(m.lead), sink = Math.min(m.wall / 2, 0.3);
|
|
258
|
+
const z0 = z - grow, top = z0 + rise + m.land + 2 * grow + fall;
|
|
259
|
+
return [[R - sink - grow, z0], [R, z0], [R + h, z0 + rise], [R + h, z0 + rise + m.land + 2 * grow], [R, top], [R - sink - grow, top]];
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* The bead to add to the box: a ring round the wall's outside, its foot (the bottom of the return face) at z = at.
|
|
263
|
+
* Union it with a box whose wall's outside is the model's diameter about the z axis.
|
|
264
|
+
* @param {object | AnnularSnap} p the joint's figures, as annularSnapModel takes them, or its model
|
|
265
|
+
* @param {object} [o] as annularSnapModel, and at: the bead's foot, mm up z (default 0); segments: faces round (default 96)
|
|
266
|
+
* @returns {object} a JSCAD geom3 with .model
|
|
267
|
+
*/
|
|
268
|
+
export function annularBead(p, o = {}) {
|
|
269
|
+
const m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96;
|
|
270
|
+
if (!isNum(at)) throw new Error(`annularBead: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
|
|
271
|
+
return Object.assign(lathe(beadOutline(m, at), n), { model: m });
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* The groove to cut from the lid's skirt, in the same place as the bead it takes (at, as annularBead's): the bead's
|
|
275
|
+
* outline grown by the clearance all round, so the seated bead touches nothing, and with mouth, the skirt's mouth's z,
|
|
276
|
+
* a lead-in cone there at the lead angle, as wide as the bead, so the skirt's edge starts over it.
|
|
277
|
+
* @param {object | AnnularSnap} p the joint's figures or its model
|
|
278
|
+
* @param {object} [o] as annularSnapModel, and at: the bead's foot (default 0); mouth: the z of the skirt's open end,
|
|
279
|
+
* below at (default none: no lead-in); segments: faces round (default 96)
|
|
280
|
+
* @returns {object} a JSCAD geom3 to subtract, with .model
|
|
281
|
+
*/
|
|
282
|
+
export function annularGroove(p, o = {}) {
|
|
283
|
+
const what = 'annularGroove', m = p?.kind === 'annular snap' ? p : annularSnapModel(p, o), at = o.at ?? 0, n = o.segments ?? 96, c = m.clearance;
|
|
284
|
+
if (!isNum(at)) throw new Error(`${what}: at is the bead's foot up z, in mm (got ${shown(o.at)})`);
|
|
285
|
+
const ring = beadOutline(m, at, c);
|
|
286
|
+
if (o.mouth == null) return Object.assign(lathe(ring, n), { model: m });
|
|
287
|
+
if (!(isNum(o.mouth) && o.mouth < at - c - 1e-9)) throw new Error(`${what}: mouth is the z of the skirt's open end, below the groove's foot at ${mm(at - c)} mm (got ${shown(o.mouth)})`);
|
|
288
|
+
// The lead-in: from the groove's full radius at the mouth up to the skirt's inside, joined to the groove by a band at
|
|
289
|
+
// the skirt's inside so the two are one cutter
|
|
290
|
+
const R = m.diameter / 2 + c, h = m.bead, rise = h / tan(m.lead), z = o.mouth - 0.1, sink = Math.min(m.wall / 2, 0.3) + c;
|
|
291
|
+
const top = Math.min(o.mouth + rise, ring[1][1]);
|
|
292
|
+
return Object.assign(lathe([[R - sink, z], [R + h, z], [R + h, o.mouth], [R + h - (top - o.mouth) * tan(m.lead), top], ...(top < ring[1][1] ? [[R, top], [R, ring[1][1]]] : []), ...ring.slice(1, -1), [R - sink, ring.at(-1)[1]]], n), { model: m });
|
|
293
|
+
}
|
package/strength.d.mts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
export function materialOf(what: any, material: any, sets: any): {
|
|
2
|
+
name: any;
|
|
3
|
+
cls: string;
|
|
4
|
+
strength: any;
|
|
5
|
+
across: any;
|
|
6
|
+
modulus: any;
|
|
7
|
+
density: any;
|
|
8
|
+
poisson: any;
|
|
9
|
+
};
|
|
10
|
+
export function weakest(mat: any): {
|
|
11
|
+
f: any;
|
|
12
|
+
note: string;
|
|
13
|
+
};
|
|
1
14
|
/**
|
|
2
15
|
* Whether enough thread is engaged, against the engagement rule for what the thread is in: 1 diameter in steel, 2 in
|
|
3
16
|
* aluminium, 2.5 in plastic (the engagement rule set of @rulecad/rules).
|
package/strength.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const options = (what, o, example) => { if (o == null || typeof o !== 'object' |
|
|
|
26
26
|
|
|
27
27
|
// A material from what a function was handed: a kit set's name ('PLA'), the workspace's set of that name (sets), or a
|
|
28
28
|
// rule set itself. Its class is told by its stiffness: under 20 GPa a plastic, under 100 GPa an aluminium, else a steel.
|
|
29
|
-
function materialOf(what, material, sets) {
|
|
29
|
+
export function materialOf(what, material, sets) {
|
|
30
30
|
if (material == null) throw new Error(`${what}: give a material, what the thread is in or the head sits on: ${MATERIALS.join(', ')}, or a rule set with a strength ({ name, rules })`);
|
|
31
31
|
let set = null;
|
|
32
32
|
if (typeof material === 'object' && material.rules && typeof material.rules === 'object') set = material;
|
|
@@ -36,10 +36,10 @@ function materialOf(what, material, sets) {
|
|
|
36
36
|
if (!set) throw new Error(`${what}: no material "${material}". There are: ${MATERIALS.join(', ')}. For another, hand in its rule set ({ name, rules: { strength, modulus } }), or the workspace's sets with it in`);
|
|
37
37
|
} else throw new Error(`${what}: material is a material's name (${MATERIALS.join(', ')}) or its rule set ({ name, rules }), not ${shown(material)}`);
|
|
38
38
|
const name = set.name ?? 'the material', num = (k) => { const f = set.rules[k]; if (f && !(isNum(f.value) && f.value > 0)) throw new Error(`${what}: ${name}.${k} is a number above 0 (got ${shown(f.value)})`); return f ? { ...f, name: `${name}.${k}` } : null; };
|
|
39
|
-
const strength = num('strength'), across = num('strength_z'), modulus = num('modulus');
|
|
39
|
+
const strength = num('strength'), across = num('strength_z'), modulus = num('modulus'), density = num('density'), poisson = num('poisson');
|
|
40
40
|
if (!strength) throw new Error(`${what}: ${name} has no strength in its rule set: a tensile or yield strength in MPa is needed`);
|
|
41
41
|
if (!modulus) throw new Error(`${what}: ${name} has no modulus in its rule set, which tells a plastic from a metal`);
|
|
42
|
-
return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus };
|
|
42
|
+
return { name, cls: modulus.value < 20000 ? 'plastic' : modulus.value < 100000 ? 'aluminium' : 'steel', strength, across, modulus, density, poisson };
|
|
43
43
|
}
|
|
44
44
|
// The class of material an engagement rule is read by: a class by name, or a material's
|
|
45
45
|
function classOf(what, material, sets) {
|
|
@@ -48,14 +48,21 @@ function classOf(what, material, sets) {
|
|
|
48
48
|
return materialOf(what, material, sets);
|
|
49
49
|
}
|
|
50
50
|
// The weaker of a printed material's two strengths, with what it says about itself
|
|
51
|
-
function weakest(mat) {
|
|
51
|
+
export function weakest(mat) {
|
|
52
52
|
const f = mat.across && mat.across.value < mat.strength.value ? mat.across : mat.strength;
|
|
53
53
|
const note = mat.cls !== 'plastic' ? '' : mat.across ? ` (${f.name}, the weaker way of the print)` : ` (${mat.name} has no strength across its layers, strength_z: the strength along them is used, and a screw standing across the layers may hold less)`;
|
|
54
54
|
return { f, note };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// A screw's own strength: its tensile stress area, and its proof load from its property class
|
|
58
|
+
// A printed bolt (a screw named with the word printed) is refused by name: it has no property class, so no proof load,
|
|
59
|
+
// preload or torque. A printed nut is let through: the screw in it is a bought one
|
|
60
|
+
function notPrinted(what, fx) {
|
|
61
|
+
if (fx.printed && fx.item !== 'nut') throw new Error(`${what}: ${fx.name} is a printed bolt, with no property class and no proof load: it is plastic, done up by hand, and breaks at its plastic's strength. Its breaking load and the margin on a pull are printedBoltModel('${fx.name}', { material, load })${what === 'seating' ? '; the pressure under its head is seating with a force (N) given' : ''}`);
|
|
62
|
+
return fx;
|
|
63
|
+
}
|
|
58
64
|
function proofOf(what, fx, o) {
|
|
65
|
+
notPrinted(what, fx);
|
|
59
66
|
if (fx.form === 'plastic') throw new Error(`${what}: ${fx.thread} is a thread-forming screw for plastic, with no property class in its rule set (${fx.set}): its maker's sheet gives what it holds`);
|
|
60
67
|
const kind = oneOf(what, 'screw', o.screw ?? 'steel', ['steel', 'stainless']), name = kind === 'steel' ? 'proof_stress' : 'stainless_proof_stress';
|
|
61
68
|
if (o.proof != null) positive(what, 'proof (the screw\'s proof stress, in MPa)', o.proof);
|
|
@@ -141,6 +148,7 @@ export function preload(m, o = {}) {
|
|
|
141
148
|
export function torqueFor(m, o = {}) {
|
|
142
149
|
options('torqueFor', o, '{ force: 500 }');
|
|
143
150
|
if (o.torque != null) throw new Error('torqueFor: give force (N), the clamp force wanted: for the force a torque gives, use preload');
|
|
151
|
+
notPrinted('torqueFor', fixingOf('torqueFor', m, o));
|
|
144
152
|
return preload(m, o);
|
|
145
153
|
}
|
|
146
154
|
|
|
@@ -163,7 +171,7 @@ export function seating(m, o = {}) {
|
|
|
163
171
|
if (form === 'set') throw new Error(`${what}: a set screw has no head to bear on anything: it presses with its point`);
|
|
164
172
|
const head = headOf(what, fx, form), mat = materialOf(what, o.material, o.sets), kind = oneOf(what, 'hole', o.hole ?? 'clearance', ['clearance', 'close', 'loose']), h = holeModel(fx, { kind, printer: o.printer });
|
|
165
173
|
if (o.force != null && o.torque != null) throw new Error(`${what}: give force (N) or torque (N·m), not both`);
|
|
166
|
-
const K = o.K ?? DEFAULTS.nut_factor.value, screw = proofOf(what, fx, o)
|
|
174
|
+
const K = o.K ?? DEFAULTS.nut_factor.value, given = o.force != null || o.torque != null, screw = given ? null : proofOf(what, fx, o); // (the screw's proof load sets the force only when none is given)
|
|
167
175
|
if (!(isNum(K) && K > 0)) throw new Error(`${what}: K is the nut factor, a number above 0 (got ${shown(o.K)})`);
|
|
168
176
|
const force = o.force != null ? positive(what, 'force (in N)', o.force) : o.torque != null ? (positive(what, 'torque (in N·m)', o.torque) * 1000) / (K * fx.major) : DEFAULTS.preload_share.value * screw.load;
|
|
169
177
|
const across = head.flats ?? head.diameter, ring = (D) => (Math.PI / 4) * (D * D - h.diameter ** 2), area = ring(across), { f } = weakest(mat), limit = f.value, pressure = force / area, within = pressure <= limit + 1e-9;
|
|
@@ -241,10 +249,10 @@ export function lengthFor(stack, m, o = {}) {
|
|
|
241
249
|
let washer = 0; if (o.washer) { if (!fx.made.washer) throw new Error(`${what}: ${fx.thread} has no washer in its rule set (${fx.set})`); washer = figure(what, fx, 'washer_thickness'); rests.push(rest(cite(fx, 'washer_thickness'), fx.figures.washer_thickness)); }
|
|
242
250
|
const total = parts.reduce((s, t) => s + t, 0), grip = r3(total + washer - (o.sunk ?? 0));
|
|
243
251
|
if (!(grip > 0)) throw new Error(`${what}: a seat sunk ${mm(o.sunk)} mm is deeper than the ${mm(total)} mm stack it is in: nothing is left under the head`);
|
|
244
|
-
const sold = fx.figures.lengths?.value;
|
|
252
|
+
const sold = fx.printed ? Array.from({ length: 300 }, (_, i) => i + 1) : fx.figures.lengths?.value; // (a printed screw is printed to any whole millimetre)
|
|
245
253
|
if (!Array.isArray(sold) || !sold.every(isNum)) throw new Error(`${what}: ${fx.thread} lists no lengths in its rule set (${fx.set}), so none can be chosen: the length wanted is between ${mm(r3(grip + end.need))} mm${Number.isFinite(end.room) ? ` and ${mm(r3(grip + end.room - end.tip))} mm` : ' and as long as you like'}`);
|
|
246
|
-
rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
|
|
247
|
-
const most = end.room - end.tip, verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'), name = (L) => screwName(fx, L, form)
|
|
254
|
+
if (!fx.printed) rests.push(rest(cite(fx, 'lengths'), fx.figures.lengths));
|
|
255
|
+
const most = end.room - end.tip, verdict = (L) => (L - grip < end.need - 1e-9 ? 'short' : L - grip > most + 1e-9 ? 'long' : 'fits'), name = (L) => `${screwName(fx, L, form)}${fx.printed ? ' printed' : ''}`;
|
|
248
256
|
const lengths = sold.map((L) => ({ length: L, name: name(L), engaged: r3(Math.max(L - grip, 0)), fits: verdict(L) })), pick = lengths.find((l) => l.fits === 'fits'), below = lengths.filter((l) => l.fits === 'short').at(-1), above = lengths.find((l) => l.fits === 'long');
|
|
249
257
|
if (most < end.need - 1e-9) throw new Error(`${what}: ${end.says} leaves ${mm(r3(most))} mm of room for the screw (${end.why}) where ${mm(end.need)} mm of thread is asked: no length can do both. Deepen the far end to ${mm(r3(end.need + end.tip))} mm or more`);
|
|
250
258
|
const short = (l) => (l.length <= grip ? `${l.name} does not reach through the ${mm(grip)} mm stack` : `${l.name} would engage ${mm(l.engaged)} mm where ${mm(end.need)} mm is asked`), long = (l) => `${l.name} would ${end.ends}: ${mm(l.engaged)} mm into ${mm(r3(most))} mm of room (${end.why})`;
|
|
@@ -326,7 +334,7 @@ export function screwGroup(places, o = {}) {
|
|
|
326
334
|
export function screwLoad(m, o = {}) {
|
|
327
335
|
const what = 'screwLoad';
|
|
328
336
|
options(what, o, '{ tension: 20, depth: 5, material: \'pla\' }');
|
|
329
|
-
const fx = fixingOf(what, m, o), num = (k, v) => { if (v != null && !(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`); return v ?? 0; };
|
|
337
|
+
const fx = notPrinted(what, fixingOf(what, m, o)), num = (k, v) => { if (v != null && !(isNum(v) && v >= 0)) throw new Error(`${what}: ${k} is a number of N, 0 or more (got ${shown(v)})`); return v ?? 0; };
|
|
330
338
|
const T = Math.max(0, isNum(o.tension) ? o.tension : num('tension', o.tension)), S = num('shear', o.shear), mu = o.friction ?? DEFAULTS.clamp_friction.value;
|
|
331
339
|
if (!(isNum(mu) && mu > 0)) throw new Error(`${what}: friction is a number above 0 (got ${shown(o.friction)})`);
|
|
332
340
|
if (o.most != null) positive(what, 'most (the clamp force the seat takes, in N)', o.most);
|