@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/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,42 @@ What changed in each release, for someone upgrading a workspace. A **printed siz
|
|
|
4
4
|
print (a hole's diameter, a seat's depth, a part's outline). Each release says whether any printed size moved, and
|
|
5
5
|
why.
|
|
6
6
|
|
|
7
|
+
## 0.2.0: a boss diameter for threads formed in plastic; an unused figure removed; the long findings and comments are written in short lines; needs Node 22.13 or later, the version the kit is tested on
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `DEFAULTS.boss_diameter`: plastic a screw forms or cuts its own thread in stands at least twice the screw's
|
|
12
|
+
diameter across round the hole, a community figure from TR Fastenings' guide for thread-forming screws. `cad check`
|
|
13
|
+
holds a pilot's, a tapped or a printed thread's wall to it (`fasten.wall`).
|
|
14
|
+
|
|
15
|
+
Upgrading: nothing changes in what this package draws or returns, besides the new figure. No printed size moves.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- A constant the code never read is gone. No printed size moves, and nothing a design or a check does changes.
|
|
20
|
+
|
|
21
|
+
- No line of the package's code runs past 120 columns any more: each long finding, error message and comment is
|
|
22
|
+
written in pieces of a line or so, joined, and a long pattern is built from two. Every finding, every message and
|
|
23
|
+
every figure is word for word as before; nothing the package draws or works out has changed.
|
|
24
|
+
|
|
25
|
+
Upgrading: nothing to do. cad keys its cached builds on the code of the packages a design uses, so a design that uses
|
|
26
|
+
fixings is built afresh once, with the same results. No printed size moves.
|
|
27
|
+
|
|
28
|
+
- @rulecad/fixings now states Node 22.13 or later in its `engines`, the same lowest Node as every rulecad package, and
|
|
29
|
+
the tests run on exactly Node 22.13.0 as well as the newest Node 24. Node 20 reached the end of its support on 30
|
|
30
|
+
April 2026, and the kit's packages stated five different lowest versions, some of them too low: on Node 20.6 to 20.9
|
|
31
|
+
`cad` stopped at start-up with "Unexpected token 'with'", and on Node 22.0 to 22.12 every `cad` command that runs a
|
|
32
|
+
design stops, because the sandbox designs run in cannot start there. npm gave no warning at install for either.
|
|
33
|
+
|
|
34
|
+
Upgrading: on a Node older than 22.13, npm now warns at install that this package needs Node 22.13; install Node 22.13
|
|
35
|
+
or later (24 recommended). Nothing else changes, and no printed size moves.
|
|
36
|
+
|
|
37
|
+
## 0.1.9: screwLoad's torque to tighten to keeps a plastic thread to half its stripping load
|
|
38
|
+
|
|
39
|
+
### Fixed
|
|
40
|
+
|
|
41
|
+
- With no torque given, `screwLoad` chose the preload that left a thread in plastic twice the pull, so with little pull it said to tighten to 97 to 99% of the thread's estimated stripping load, and passed. A stripping load is an estimate and a torque's clamp scatters by a quarter to a third, so a maker who followed it could strip the thread on assembly. The preload it chooses now leaves the thread `fixings.load_margin` (twice) the preload and the pull together, within half of `most` (what the seat takes) and three quarters of the proof load: never more than half the stripping load. The thread's margin is now its stripping load over the preload and the pull together (`margins.thread`, and the finding's words: "It holds 2.03 times the preload and the load, the thread first"), where it was the pull over what the preload left; with no pull it is no longer "any number of" times. The finding says how much a torque's clamp scatters. If you upgrade, the torques recommended for screws in printed threads fall by about half (M3 in PLA 6 mm deep: 0.33 N·m where it was 0.66), and where `most` sets it, for a screw in a nut or an insert too, a torque given that clamps with more than half the stripping load now warns, and some joints that passed now warn that the lighter clamp holds their shear by friction fewer than twice over. No printed size changes.
|
|
42
|
+
|
|
7
43
|
## 0.1.8: ABS, ASA and PA-CF in thread engagement
|
|
8
44
|
### Added
|
|
9
45
|
|
package/README.md
CHANGED
|
@@ -457,7 +457,7 @@ or a rule set with a `strength` and a `modulus`. Its class (plastic, aluminium o
|
|
|
457
457
|
| `seating(m, { head, material, force })` | The pressure under the head, the plain washer that would bring it within, and the most the seat takes. `torque` in place of `force`; with neither, a screw tightened fully |
|
|
458
458
|
| `lengthFor(stack, m, { into })` | The shortest sold length that passes the stack and engages enough at the far end without bottoming out or standing proud |
|
|
459
459
|
| `screwGroup(places, { force, moment, at, pivot })` | A load on a joint shared between its screws: each one's shear across the joint and pull along it. `places` are the screws' `[x, y]` across the joint; `force` and `moment` are on the part they hold, `z` along the screws and positive pulling it off |
|
|
460
|
-
| `screwLoad(m, { tension, shear, depth, material, torque })` | One screw under its share: how many times that load it holds before the screw yields and the thread
|
|
460
|
+
| `screwLoad(m, { tension, shear, depth, material, torque })` | One screw under its share: how many times that load it holds before the screw yields, how many times the preload and the pull together the thread takes before it strips, and whether the parts slip. With no `torque`, the preload that leaves the thread `fixings.load_margin` (twice) the preload and the pull, within half of `most` (what the seat takes) and three quarters of the proof load, and the torque for it, rounded down: never more than half the thread's estimated stripping load, since that load is an estimate and a torque's clamp scatters by a quarter to a third |
|
|
461
461
|
|
|
462
462
|
The screw is class 8.8 steel as its rule set gives it. `screw: 'stainless'` takes the A2-70 figure, and
|
|
463
463
|
`proof: 830` any other class by its proof stress in MPa (830 is class 10.9). A fixing's name carries no property
|
package/bolts.d.mts
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
2
|
+
* @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
|
|
3
|
+
* nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
|
|
4
|
+
* root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip:
|
|
5
|
+
* { area: number, shear: number, load: number, nutArea: number | null }, headShear: number | null, breaking: number,
|
|
6
|
+
* governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object,
|
|
7
|
+
* rests: object[], findings: object[] }} PrintedBolt root: the bolt's root diameter as drawn, mm; rootArea: its
|
|
8
|
+
* section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
|
|
9
|
+
* is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
|
|
10
|
+
* the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
|
|
11
|
+
* the load that shears the head off the shank; breaking: the least of the three, N, governs: which
|
|
9
12
|
*/
|
|
10
13
|
/**
|
|
11
14
|
* A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
|
|
12
15
|
* load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
|
|
13
16
|
* across its layers; lying on a flat (axis x or y), along them.
|
|
14
|
-
* @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
|
|
15
|
-
*
|
|
17
|
+
* @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
|
|
18
|
+
* { length, head }
|
|
19
|
+
* @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number,
|
|
20
|
+
* axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
|
|
16
21
|
* gap?: number, sets?: object }} [o]
|
|
17
22
|
* material: the plastic (default PLA); nut: printed (a printed nut or a thread printed in the part, the default) or
|
|
18
|
-
* steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
|
|
19
|
-
* prints, z standing on its head (the default), or x or y lying
|
|
20
|
-
* fixings.load_margin; gap: in place of the printer's thread_gap
|
|
23
|
+
* steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
|
|
24
|
+
* (default the thread's hex nut height); axis: how it prints, z standing on its head (the default), or x or y lying
|
|
25
|
+
* on a flat; load: the pull along it, N, held to fixings.load_margin; gap: in place of the printer's thread_gap
|
|
21
26
|
* @returns {PrintedBolt}
|
|
22
27
|
*/
|
|
23
28
|
export function printedBoltModel(m: string | object, o?: {
|
|
@@ -35,20 +40,23 @@ export function printedBoltModel(m: string | object, o?: {
|
|
|
35
40
|
/**
|
|
36
41
|
* A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
|
|
37
42
|
* as it prints: the head's top on the bed at z = 0, its tip up.
|
|
38
|
-
* @param {string | object} m as printedBoltModel @param {object} [o] as
|
|
43
|
+
* @param {string | object} m as printedBoltModel @param {object} [o] as
|
|
44
|
+
* printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
|
|
39
45
|
* @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
|
|
40
46
|
*/
|
|
41
47
|
export function printedBolt(m: string | object, o?: object, ops?: {
|
|
42
48
|
union: Function;
|
|
43
49
|
subtract: Function;
|
|
44
50
|
}): object;
|
|
45
|
-
/** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard
|
|
51
|
+
/** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard
|
|
52
|
+
* thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
|
|
46
53
|
export const BOLT_NUTS: string[];
|
|
47
54
|
/**
|
|
48
|
-
* root: the bolt's root diameter as drawn, mm; rootArea: its
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
55
|
+
* root: the bolt's root diameter as drawn, mm; rootArea: its
|
|
56
|
+
* section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
|
|
57
|
+
* is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
|
|
58
|
+
* the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
|
|
59
|
+
* the load that shears the head off the shank; breaking: the least of the three, N, governs: which
|
|
52
60
|
*/
|
|
53
61
|
export type PrintedBolt = {
|
|
54
62
|
kind: "printed-bolt";
|
package/bolts.mjs
CHANGED
|
@@ -13,94 +13,246 @@ import { screwModel, screw } from './hardware.mjs';
|
|
|
13
13
|
|
|
14
14
|
const { translate, rotateX } = jscad.transforms;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
16
|
+
// (a plain word's article: model's a() is for thread names)
|
|
17
|
+
const an = (w) => `${/^[aeiou]/i.test(w) ? 'an' : 'a'} ${w}`;
|
|
18
|
+
const n1 = (x) => +x.toFixed(1),
|
|
19
|
+
n2 = (x) => +x.toFixed(2);
|
|
20
|
+
/** What a printed bolt can go in: a printed nut or a thread printed in the part (half the gap each), or a standard
|
|
21
|
+
* thread, 'steel': a bought nut, a heat-set insert or a tapped hole (the bolt takes the whole gap). */
|
|
19
22
|
export const BOLT_NUTS = ['printed', 'steel'];
|
|
20
23
|
|
|
21
|
-
// The area of a circle of radius r less the segment past a chord f from its centre (a bolt lying on its side, on its
|
|
22
|
-
|
|
24
|
+
// The area of a circle of radius r less the segment past a chord f from its centre (a bolt lying on its side, on its
|
|
25
|
+
// flat)
|
|
26
|
+
const segmentless = (r, f) =>
|
|
27
|
+
f == null || f >= r ? Math.PI * r * r : Math.PI * r * r - (r * r * Math.acos(f / r) - f * Math.sqrt(r * r - f * f));
|
|
23
28
|
|
|
24
29
|
/**
|
|
25
|
-
* @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* @typedef {{ kind: 'printed-bolt', name: string, thread: string, head: string, length: number,
|
|
31
|
+
* nut: 'printed' | 'steel', axis: 'x' | 'y' | 'z', material: string,
|
|
32
|
+
* root: number, rootArea: number, engaged: number, tension: { strength: number, load: number, rule: string }, strip:
|
|
33
|
+
* { area: number, shear: number, load: number, nutArea: number | null }, headShear: number | null, breaking: number,
|
|
34
|
+
* governs: 'tension' | 'strip' | 'head', load: number | null, margin: number | null, grams: number, threaded: object,
|
|
35
|
+
* rests: object[], findings: object[] }} PrintedBolt root: the bolt's root diameter as drawn, mm; rootArea: its
|
|
36
|
+
* section there (less its flat, lying), mm²; engaged: thread in the nut, mm; tension: the plastic's strength the root
|
|
37
|
+
* is pulled at (across its layers standing, along them lying) and the load it breaks at, N; strip: the shear area of
|
|
38
|
+
* the bolt's teeth in the nut (and of a printed nut's own), the shear strength and the load they shear at; headShear:
|
|
39
|
+
* the load that shears the head off the shank; breaking: the least of the three, N, governs: which
|
|
32
40
|
*/
|
|
33
41
|
|
|
34
42
|
/**
|
|
35
43
|
* A printed bolt's strength: the load along it that breaks it, from the plastic's strength by how it prints, and that
|
|
36
44
|
* load against the one it carries. Standing on its head (axis z, the way it prints with no support), the pull goes
|
|
37
45
|
* across its layers; lying on a flat (axis x or y), along them.
|
|
38
|
-
* @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
|
|
39
|
-
*
|
|
46
|
+
* @param {string | object} m a screw's name or model ('M8x20 hex printed', or 'M8x20 hex'), or a thread with
|
|
47
|
+
* { length, head }
|
|
48
|
+
* @param {{ material?: string | object, printer?: object, nut?: 'printed' | 'steel', depth?: number,
|
|
49
|
+
* axis?: 'x' | 'y' | 'z', load?: number, length?: number, head?: string,
|
|
40
50
|
* gap?: number, sets?: object }} [o]
|
|
41
51
|
* material: the plastic (default PLA); nut: printed (a printed nut or a thread printed in the part, the default) or
|
|
42
|
-
* steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
|
|
43
|
-
* prints, z standing on its head (the default), or x or y lying
|
|
44
|
-
* fixings.load_margin; gap: in place of the printer's thread_gap
|
|
52
|
+
* steel (a standard thread: a bought nut, a heat-set insert or a tapped hole); depth: thread engaged in the nut, mm
|
|
53
|
+
* (default the thread's hex nut height); axis: how it prints, z standing on its head (the default), or x or y lying
|
|
54
|
+
* on a flat; load: the pull along it, N, held to fixings.load_margin; gap: in place of the printer's thread_gap
|
|
45
55
|
* @returns {PrintedBolt}
|
|
46
56
|
*/
|
|
47
57
|
export function printedBoltModel(m, o = {}) {
|
|
48
58
|
const what = 'printedBoltModel';
|
|
49
|
-
optionsOf(what, o,
|
|
59
|
+
optionsOf(what, o, "{ material: 'pla', load: 100 }");
|
|
50
60
|
const fx = fixingOf(what, m, { ...o, anyLength: true });
|
|
51
|
-
if (!['screw', 'thread'].includes(fx.item))
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
if (!['screw', 'thread'].includes(fx.item))
|
|
62
|
+
throw new Error(`${what}: ${fx.name} is ${an(fx.item)}, not a bolt: name a screw ('${fx.thread}x20 hex printed')`);
|
|
63
|
+
const nut = oneOf(what, 'nut', o.nut ?? 'printed', BOLT_NUTS),
|
|
64
|
+
axis = oneOf(what, 'axis', o.axis ?? 'z', ['x', 'y', 'z']),
|
|
65
|
+
mat = materialOf(what, o.material ?? 'pla', o.sets);
|
|
66
|
+
if (mat.cls !== 'plastic')
|
|
67
|
+
throw new Error(
|
|
68
|
+
`${what}: ${mat.name} is ${an(mat.cls)}, not a plastic: a printed bolt is printed in a plastic (pla, ` +
|
|
69
|
+
`petg, or a plastic's rule set)`,
|
|
70
|
+
);
|
|
71
|
+
const form = o.head ?? fx.head?.form ?? (fx.made.heads.includes('hex') ? 'hex' : fx.made.heads[0]),
|
|
72
|
+
sc = screwModel(fx, {
|
|
73
|
+
length: o.length ?? fx.length ?? undefined,
|
|
74
|
+
head: form,
|
|
75
|
+
anyLength: true,
|
|
76
|
+
...(fx.printed ? { material: o.material ?? 'pla', sets: o.sets } : {}),
|
|
77
|
+
}); // (a printed name is weighed in its plastic by screwModel)
|
|
78
|
+
const out = [],
|
|
79
|
+
rests = [];
|
|
80
|
+
// Its thread, as it prints: refused where the printer cannot resolve the pitch, naming the smallest thread that
|
|
81
|
+
// prints
|
|
82
|
+
const shank = r3(sc.length - sc.sink),
|
|
83
|
+
t = threadModel(fx, {
|
|
84
|
+
what,
|
|
85
|
+
length: shank,
|
|
86
|
+
printer: o.printer,
|
|
87
|
+
sets: o.sets,
|
|
88
|
+
mate: nut === 'printed' ? 'printed' : 'bought',
|
|
89
|
+
gap: o.gap,
|
|
90
|
+
top: '-z',
|
|
91
|
+
axis,
|
|
92
|
+
flat: axis !== 'z' ? true : undefined,
|
|
93
|
+
});
|
|
94
|
+
rests.push(...t.rests);
|
|
95
|
+
out.push(...t.findings.filter((f) => f.code !== 'thread.overlap'));
|
|
96
|
+
const depth =
|
|
97
|
+
o.depth != null ? positive(what, 'depth (thread engaged in the nut)', o.depth) : nutOf(what, fx, 'hex').height;
|
|
60
98
|
if (o.depth == null) rests.push(rest(cite(fx, 'nut_height'), fx.figures.nut_height));
|
|
61
99
|
// Tension across the root as drawn: standing, the pull goes across the layers; lying, along them
|
|
62
|
-
const root = t.drawn.minor,
|
|
100
|
+
const root = t.drawn.minor,
|
|
101
|
+
rootArea = segmentless(root / 2, t.flat),
|
|
102
|
+
w = weakest(mat),
|
|
103
|
+
sTension = axis === 'z' ? w.f : mat.strength,
|
|
104
|
+
tensionLoad = sTension.value * rootArea;
|
|
63
105
|
rests.push(rest(sTension.name, sTension));
|
|
64
|
-
// The teeth in the nut, on the basic profile: the bolt's at the nut's minor diameter D1 = d - 1.0825 P, a tooth 0.75
|
|
65
|
-
// wide there (the nut's crest flat is P/4); a printed nut's own at the bolt's major d, 0.875 P wide (the bolt's
|
|
66
|
-
|
|
67
|
-
const
|
|
106
|
+
// The teeth in the nut, on the basic profile: the bolt's at the nut's minor diameter D1 = d - 1.0825 P, a tooth 0.75
|
|
107
|
+
// P wide there (the nut's crest flat is P/4); a printed nut's own at the bolt's major d, 0.875 P wide (the bolt's
|
|
108
|
+
// crest is P/8)
|
|
109
|
+
const P = fx.pitch,
|
|
110
|
+
d = fx.major,
|
|
111
|
+
D1 = d - (5 / 8) * Math.sqrt(3) * P,
|
|
112
|
+
ratio = DEFAULTS.shear_ratio.value,
|
|
113
|
+
tau = w.f.value * ratio;
|
|
114
|
+
const boltArea = 0.75 * Math.PI * D1 * depth,
|
|
115
|
+
nutArea = nut === 'printed' ? 0.875 * Math.PI * d * depth : null,
|
|
116
|
+
stripArea = Math.min(boltArea, nutArea ?? Infinity),
|
|
117
|
+
stripLoad = tau * stripArea;
|
|
68
118
|
rests.push(rest(w.f.name, w.f), rest('fixings.shear_ratio', DEFAULTS.shear_ratio));
|
|
69
119
|
// The head off its shank: a cylinder the bolt's diameter, the head's height tall, across the layers
|
|
70
120
|
const headShear = form === 'set' ? null : tau * Math.PI * d * Math.max(sc.headHeight, 1e-9);
|
|
71
121
|
const caps = { tension: tensionLoad, strip: stripLoad, ...(headShear != null ? { head: headShear } : {}) };
|
|
72
|
-
const governs = /** @type {'tension' | 'strip' | 'head'} */ (Object.entries(caps).sort((x, y) => x[1] - y[1])[0][0]),
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
122
|
+
const governs = /** @type {'tension' | 'strip' | 'head'} */ (Object.entries(caps).sort((x, y) => x[1] - y[1])[0][0]),
|
|
123
|
+
breaking = caps[governs];
|
|
124
|
+
const across =
|
|
125
|
+
axis === 'z'
|
|
126
|
+
? `across its layers (it prints standing on its head)${w.note}`
|
|
127
|
+
: 'along its layers (it prints lying on a flat)';
|
|
128
|
+
out.push(
|
|
129
|
+
finding(
|
|
130
|
+
'info',
|
|
131
|
+
`${a(fx.thread)} printed bolt in ${mat.name} breaks at about ${mm(n1(breaking))} N, ` +
|
|
132
|
+
(governs === 'tension'
|
|
133
|
+
? 'pulled apart across its root'
|
|
134
|
+
: governs === 'strip'
|
|
135
|
+
? 'its teeth sheared off in the nut'
|
|
136
|
+
: 'its head sheared off') +
|
|
137
|
+
`: its ${mm(root)} mm root, ${mm(n2(rootArea))} mm², pulled ${across} at ${sTension.name} ` +
|
|
138
|
+
`${mm(sTension.value)} MPa, ${mm(n1(tensionLoad))} N; ${mm(depth)} mm of thread in a ${nut} nut shears ` +
|
|
139
|
+
`its ` +
|
|
140
|
+
(nut === 'printed' ? 'weaker teeth' : 'teeth') +
|
|
141
|
+
` over ${mm(n2(stripArea))} mm² (0.75 π D1 Le` +
|
|
142
|
+
(nut === 'printed' ? ", the nut's own 0.875 π d Le" : '') +
|
|
143
|
+
`) at ${mm(n2(tau))} MPa, ${mm(n1(stripLoad))} N` +
|
|
144
|
+
(headShear != null ? `; its ${mm(sc.headHeight)} mm head shears off at ${mm(n1(headShear))} N` : '') +
|
|
145
|
+
`. Every strength is an estimate: test one that matters`,
|
|
146
|
+
'bolt.strength',
|
|
147
|
+
{
|
|
148
|
+
values: {
|
|
149
|
+
breaking: n1(breaking),
|
|
150
|
+
tension: n1(tensionLoad),
|
|
151
|
+
strip: n1(stripLoad),
|
|
152
|
+
head: headShear != null ? n1(headShear) : null,
|
|
153
|
+
governs,
|
|
154
|
+
},
|
|
155
|
+
refs: { thread: fx.thread, material: mat.name, nut, axis, kind: 'estimate' },
|
|
156
|
+
},
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
const load = o.load != null ? positive(what, 'load (the pull along the bolt, in N)', o.load) : null,
|
|
160
|
+
want = DEFAULTS.load_margin.value;
|
|
77
161
|
let margin = null;
|
|
78
162
|
if (load != null) {
|
|
79
|
-
margin = n2(breaking / load);
|
|
80
|
-
|
|
163
|
+
margin = n2(breaking / load);
|
|
164
|
+
rests.push(rest('fixings.load_margin', DEFAULTS.load_margin));
|
|
165
|
+
out.push(
|
|
166
|
+
finding(
|
|
167
|
+
margin >= want ? 'pass' : margin >= 1 ? 'warn' : 'fail',
|
|
168
|
+
`a pull of ${mm(load)} N on the printed bolt is held ${mm(margin)} times over` +
|
|
169
|
+
(margin >= want
|
|
170
|
+
? ''
|
|
171
|
+
: margin >= 1
|
|
172
|
+
? `, under the ${mm(want)} times fixings.load_margin asks`
|
|
173
|
+
: ': it breaks') +
|
|
174
|
+
` (${governs} first). Do it up by hand: a printed thread takes no wrench's torque`,
|
|
175
|
+
'bolt.load',
|
|
176
|
+
{ values: { load, margin, breaking: n1(breaking) } },
|
|
177
|
+
),
|
|
178
|
+
);
|
|
81
179
|
}
|
|
82
|
-
if (nut === 'steel')
|
|
180
|
+
if (nut === 'steel')
|
|
181
|
+
out.push(
|
|
182
|
+
finding(
|
|
183
|
+
'info',
|
|
184
|
+
`in a standard thread (a bought steel nut, a heat-set insert or a tapped hole), the printed bolt ` +
|
|
185
|
+
`takes the whole of the thread's gap and the nut's teeth hold: the bolt's teeth shear first`,
|
|
186
|
+
'bolt.nut',
|
|
187
|
+
{ values: { nut } },
|
|
188
|
+
),
|
|
189
|
+
);
|
|
83
190
|
// Its mass: the outline screwModel weighs, at the plastic's density
|
|
84
|
-
if (!mat.density)
|
|
191
|
+
if (!mat.density)
|
|
192
|
+
throw new Error(`${what}: ${mat.name} has no density in its rule set, so the bolt cannot be weighed`);
|
|
85
193
|
const grams = fx.printed ? sc.mass : r3((sc.mass / DEFAULTS.steel_density.value) * mat.density.value);
|
|
86
194
|
rests.push(rest(mat.density.name, mat.density));
|
|
87
195
|
const name = fx.printed ? sc.name : `${sc.name} printed`;
|
|
88
|
-
out.push(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
196
|
+
out.push(
|
|
197
|
+
finding('info', `${name} weighs ${mm(grams)} g of ${mat.name}, an estimate from its outline`, 'bolt.mass', {
|
|
198
|
+
values: { grams },
|
|
199
|
+
}),
|
|
200
|
+
);
|
|
201
|
+
return {
|
|
202
|
+
kind: 'printed-bolt',
|
|
203
|
+
name,
|
|
204
|
+
thread: fx.thread,
|
|
205
|
+
head: form,
|
|
206
|
+
length: sc.length,
|
|
207
|
+
nut,
|
|
208
|
+
axis,
|
|
209
|
+
material: mat.name,
|
|
210
|
+
root,
|
|
211
|
+
rootArea: n2(rootArea),
|
|
212
|
+
engaged: depth,
|
|
213
|
+
tension: { strength: sTension.value, load: n1(tensionLoad), rule: sTension.name },
|
|
214
|
+
strip: { area: n2(stripArea), shear: n2(tau), load: n1(stripLoad), nutArea: nutArea != null ? n2(nutArea) : null },
|
|
215
|
+
headShear: headShear != null ? n1(headShear) : null,
|
|
216
|
+
breaking: n1(breaking),
|
|
217
|
+
governs,
|
|
218
|
+
load,
|
|
219
|
+
margin,
|
|
220
|
+
grams,
|
|
221
|
+
threaded: t,
|
|
222
|
+
rests,
|
|
223
|
+
findings: out,
|
|
224
|
+
};
|
|
92
225
|
}
|
|
93
226
|
|
|
94
227
|
/**
|
|
95
228
|
* A printed bolt's solid: the screw with its thread drawn (screw's display: 'thread'), turned over to stand on its head
|
|
96
229
|
* as it prints: the head's top on the bed at z = 0, its tip up.
|
|
97
|
-
* @param {string | object} m as printedBoltModel @param {object} [o] as
|
|
230
|
+
* @param {string | object} m as printedBoltModel @param {object} [o] as
|
|
231
|
+
* printedBoltModel @param {{ union: Function, subtract: Function }} [ops]
|
|
98
232
|
* @returns {object} a JSCAD geom3 with .model holding printedBoltModel's numbers
|
|
99
233
|
*/
|
|
100
234
|
export function printedBolt(m, o = {}, ops) {
|
|
101
|
-
const b = printedBoltModel(m, o),
|
|
102
|
-
|
|
103
|
-
|
|
235
|
+
const b = printedBoltModel(m, o),
|
|
236
|
+
fx = fixingOf('printedBolt', m, { ...o, anyLength: true });
|
|
237
|
+
if (b.axis !== 'z')
|
|
238
|
+
throw new Error(
|
|
239
|
+
'printedBolt: the solid is drawn standing on its head (axis z); a bolt lying on its flat is ' +
|
|
240
|
+
'thread(..., { axis, flat: true }) with a head of your own',
|
|
241
|
+
);
|
|
242
|
+
const g = screw(
|
|
243
|
+
fx,
|
|
244
|
+
{
|
|
245
|
+
length: b.length,
|
|
246
|
+
head: b.head,
|
|
247
|
+
anyLength: true,
|
|
248
|
+
display: 'thread',
|
|
249
|
+
printer: o.printer,
|
|
250
|
+
sets: o.sets,
|
|
251
|
+
mate: b.nut === 'printed' ? 'printed' : 'bought',
|
|
252
|
+
gap: o.gap,
|
|
253
|
+
},
|
|
254
|
+
...(ops ? [ops] : []),
|
|
255
|
+
);
|
|
104
256
|
// (turned over onto its head, the head's top on the bed at z = 0 and its tip up)
|
|
105
257
|
return Object.assign(translate([0, 0, g.model.top], rotateX(Math.PI, g)), { model: b, screw: g.model });
|
|
106
258
|
}
|
package/draw.d.mts
CHANGED
|
@@ -8,7 +8,8 @@ export function along(g: any, into: any, at?: number[]): any;
|
|
|
8
8
|
* @returns {object} a JSCAD geom3
|
|
9
9
|
*/
|
|
10
10
|
export function lathe(profile: number[][], n?: number, phase?: number): object;
|
|
11
|
-
/** The volume a profile turns into, with true circles: each edge a frustum
|
|
11
|
+
/** The volume a profile turns into, with true circles: each edge a frustum
|
|
12
|
+
* (mm³). @param {number[][]} profile @returns {number} */
|
|
12
13
|
export function turnedVolume(profile: number[][]): number;
|
|
13
14
|
/**
|
|
14
15
|
* A round cutter going down from z = 0, from its steps: [radius, depth] pairs from the mouth inwards, the radius
|
|
@@ -22,7 +23,8 @@ export function bore(steps: number[][], { through }?: {
|
|
|
22
23
|
* A cutter lying on its side, going down from z = 0 in its own drawing, from its steps as bore takes them: at every
|
|
23
24
|
* depth its section is a teardrop, a circle with a 45° pointed roof on the up side, so it prints with no support. One
|
|
24
25
|
* closed solid with no joins in it, for the stepped and coned cutters @rulecad/shapes has no helper for.
|
|
25
|
-
* @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
|
|
26
|
+
* @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
|
|
27
|
+
* drawing: [1, 0], [0, 1] …
|
|
26
28
|
* @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
|
|
27
29
|
*/
|
|
28
30
|
export function teardrop(steps: number[][], up: number[], { through }?: {
|
package/draw.mjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// triangles. Nothing here knows a thread: sizes come in as plain numbers.
|
|
4
4
|
import jscad from '@jscad/modeling';
|
|
5
5
|
|
|
6
|
-
const { translate, rotateX, rotateY } = jscad.transforms,
|
|
6
|
+
const { translate, rotateX, rotateY } = jscad.transforms,
|
|
7
|
+
{ geom3, poly3 } = jscad.geometries;
|
|
7
8
|
|
|
8
9
|
export const OUT = 0.1; // how far a cutter starts outside the face it enters by, so no faces lie on each other
|
|
9
10
|
export const SEGMENTS = 48; // round cutters
|
|
@@ -16,8 +17,14 @@ export const booleans = { union: jscad.booleans.union, subtract: jscad.booleans.
|
|
|
16
17
|
|
|
17
18
|
/** A cutter drawn going down from z = 0 (into -z), turned to go along `into` from the origin, then moved to `at`. */
|
|
18
19
|
export function along(g, into, at = [0, 0, 0]) {
|
|
19
|
-
const turn = {
|
|
20
|
-
'
|
|
20
|
+
const turn = {
|
|
21
|
+
'-z': (x) => x,
|
|
22
|
+
'+z': (x) => rotateX(Math.PI, x),
|
|
23
|
+
'+x': (x) => rotateY(-Math.PI / 2, x),
|
|
24
|
+
'-x': (x) => rotateY(Math.PI / 2, x),
|
|
25
|
+
'+y': (x) => rotateX(Math.PI / 2, x),
|
|
26
|
+
'-y': (x) => rotateX(-Math.PI / 2, x),
|
|
27
|
+
}[into];
|
|
21
28
|
return translate(at, turn(g));
|
|
22
29
|
}
|
|
23
30
|
|
|
@@ -29,26 +36,41 @@ export function along(g, into, at = [0, 0, 0]) {
|
|
|
29
36
|
* @returns {object} a JSCAD geom3
|
|
30
37
|
*/
|
|
31
38
|
export function lathe(profile, n = SEGMENTS, phase = 0) {
|
|
32
|
-
const ring = (r, z) =>
|
|
33
|
-
|
|
34
|
-
|
|
39
|
+
const ring = (r, z) =>
|
|
40
|
+
Array.from({ length: n }, (_, i) => {
|
|
41
|
+
const a = phase + (2 * Math.PI * i) / n;
|
|
42
|
+
return [r * Math.cos(a), r * Math.sin(a), z];
|
|
43
|
+
});
|
|
44
|
+
const pts = profile.filter(
|
|
45
|
+
(p, i) => i === 0 || Math.abs(p[0] - profile[i - 1][0]) > 1e-9 || Math.abs(p[1] - profile[i - 1][1]) > 1e-9,
|
|
46
|
+
);
|
|
47
|
+
const rings = pts.map(([r, z]) => (r > 1e-9 ? ring(r, z) : null)),
|
|
48
|
+
polys = [],
|
|
49
|
+
closed = !!rings[0] && !!rings.at(-1);
|
|
35
50
|
for (let e = 0; e < (closed ? pts.length : pts.length - 1); e++) {
|
|
36
|
-
const b = (e + 1) % pts.length,
|
|
51
|
+
const b = (e + 1) % pts.length,
|
|
52
|
+
P = rings[e],
|
|
53
|
+
Q = rings[b];
|
|
37
54
|
if (!P && !Q) continue;
|
|
38
55
|
for (let i = 0; i < n; i++) {
|
|
39
56
|
const j = (i + 1) % n;
|
|
40
|
-
polys.push(
|
|
57
|
+
polys.push(
|
|
58
|
+
!P ? [[0, 0, pts[e][1]], Q[j], Q[i]] : !Q ? [P[i], P[j], [0, 0, pts[b][1]]] : [P[i], P[j], Q[j], Q[i]],
|
|
59
|
+
);
|
|
41
60
|
}
|
|
42
61
|
}
|
|
43
62
|
return geom3.create(polys.map((p) => poly3.create(p)));
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
/** The volume a profile turns into, with true circles: each edge a frustum
|
|
65
|
+
/** The volume a profile turns into, with true circles: each edge a frustum
|
|
66
|
+
* (mm³). @param {number[][]} profile @returns {number} */
|
|
47
67
|
export function turnedVolume(profile) {
|
|
48
68
|
let v = 0;
|
|
49
69
|
for (let i = 0; i < profile.length; i++) {
|
|
50
|
-
const [r0, z0] = profile[i],
|
|
51
|
-
|
|
70
|
+
const [r0, z0] = profile[i],
|
|
71
|
+
[r1, z1] = profile[(i + 1) % profile.length];
|
|
72
|
+
// (the shoelace sum of a turned outline: edges going down the outside add, going up take away)
|
|
73
|
+
v += (Math.PI / 3) * (z0 - z1) * (r0 * r0 + r0 * r1 + r1 * r1);
|
|
52
74
|
}
|
|
53
75
|
return Math.abs(v);
|
|
54
76
|
}
|
|
@@ -59,7 +81,8 @@ export function turnedVolume(profile) {
|
|
|
59
81
|
* @param {number[][]} steps @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
|
|
60
82
|
*/
|
|
61
83
|
export function bore(steps, { through = false } = {}) {
|
|
62
|
-
const last = steps.at(-1),
|
|
84
|
+
const last = steps.at(-1),
|
|
85
|
+
end = last[1] + (through ? OUT : 0);
|
|
63
86
|
const side = [[steps[0][0], OUT], ...steps.map(([r, d]) => [r, -d])];
|
|
64
87
|
if (through) side.push([last[0], -end]);
|
|
65
88
|
return lathe([[0, -end], ...side.reverse(), [0, OUT]]);
|
|
@@ -69,17 +92,35 @@ export function bore(steps, { through = false } = {}) {
|
|
|
69
92
|
* A cutter lying on its side, going down from z = 0 in its own drawing, from its steps as bore takes them: at every
|
|
70
93
|
* depth its section is a teardrop, a circle with a 45° pointed roof on the up side, so it prints with no support. One
|
|
71
94
|
* closed solid with no joins in it, for the stepped and coned cutters @rulecad/shapes has no helper for.
|
|
72
|
-
* @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
|
|
95
|
+
* @param {number[][]} steps [radius, depth] pairs from the mouth inwards @param {number[]} up which way is up in the
|
|
96
|
+
* drawing: [1, 0], [0, 1] …
|
|
73
97
|
* @param {{ through?: boolean }} [o] @returns {object} a JSCAD geom3 to subtract
|
|
74
98
|
*/
|
|
75
99
|
export function teardrop(steps, up, { through = false } = {}) {
|
|
76
100
|
// 35 steps round: no corner then lies level with the axis or 30° off it, the only places a corner's height is a round
|
|
77
101
|
// number of mm, where it could sit exactly in the plane a slicer (or printcheck) cuts a layer at
|
|
78
|
-
const turn = Math.atan2(up[1], up[0]),
|
|
102
|
+
const turn = Math.atan2(up[1], up[0]),
|
|
103
|
+
n = 35,
|
|
104
|
+
last = steps.at(-1);
|
|
79
105
|
// the point of the roof, then the circle from 45° past it round to 45° short of it
|
|
80
|
-
const section = (r, z) => [
|
|
81
|
-
|
|
82
|
-
|
|
106
|
+
const section = (r, z) => [
|
|
107
|
+
[r * Math.SQRT2 * Math.cos(turn), r * Math.SQRT2 * Math.sin(turn), z],
|
|
108
|
+
...Array.from({ length: n + 1 }, (_, i) => {
|
|
109
|
+
const t = turn + Math.PI / 4 + (1.5 * Math.PI * i) / n;
|
|
110
|
+
return [r * Math.cos(t), r * Math.sin(t), z];
|
|
111
|
+
}),
|
|
112
|
+
];
|
|
113
|
+
const rings = [
|
|
114
|
+
[steps[0][0], OUT],
|
|
115
|
+
...steps.map(([r, d]) => [r, -d]),
|
|
116
|
+
...(through ? [[last[0], -last[1] - OUT]] : []),
|
|
117
|
+
].map(([r, z]) => section(r, z)),
|
|
118
|
+
polys = [rings[0]];
|
|
119
|
+
for (let k = 0; k < rings.length - 1; k++)
|
|
120
|
+
for (let i = 0; i < n + 2; i++) {
|
|
121
|
+
const j = (i + 1) % (n + 2);
|
|
122
|
+
polys.push([rings[k][i], rings[k + 1][i], rings[k + 1][j], rings[k][j]]);
|
|
123
|
+
}
|
|
83
124
|
polys.push([...rings.at(-1)].reverse());
|
|
84
125
|
return geom3.create(polys.map((p) => poly3.create(p)));
|
|
85
126
|
}
|
package/fixings.d.mts
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
* Every function of this package with a workspace's rule sets and printer already in hand, so a design writes
|
|
3
3
|
* `fixings.hole('M3', { kind: 'pilot' })` and gets its own project's figures. This is the hook a host such as
|
|
4
4
|
* @rulecad/cad calls once per design: the package itself reads no files.
|
|
5
|
-
* @param {{ sets?: object, printer?: object, ops?: { union: Function, subtract: Function },
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
5
|
+
* @param {{ sets?: object, printer?: object, ops?: { union: Function, subtract: Function },
|
|
6
|
+
* display?: 'thread' | 'plain' }} [workspace]
|
|
7
|
+
* sets: the workspace's rule sets, by name ({ m3: { name, rules } }) or as a list: one for a thread is used before
|
|
8
|
+
* the kit's; printer: the printer's rule set ({ name, rules }, so each figure keeps its kind and source) or its
|
|
9
|
+
* values; ops: the design's booleans (v.ops); display: how a printed thread is drawn where a call does not say
|
|
10
|
+
* (thread and a hole of kind 'thread'): 'plain' for a viewer or a link, where a real thread's thousands of triangles
|
|
11
|
+
* are not wanted
|
|
12
|
+
* @returns {Record<string, Function>} fixingModel(name, change, opts) and the rest, each taking (fixing, options);
|
|
13
|
+
* lengthFor takes (stack, fixing, options)
|
|
11
14
|
*/
|
|
12
15
|
export function fixingsFor({ sets, printer, ops, display }?: {
|
|
13
16
|
sets?: object;
|