@rulecad/gears 0.3.5 → 0.4.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 +66 -0
- package/contact.mjs +127 -36
- package/core.mjs +867 -212
- package/diagram.mjs +134 -31
- package/gears.mjs +8 -1
- package/package.json +3 -3
- package/planetary.mjs +264 -74
- package/tooth.mjs +123 -37
- package/worm.mjs +139 -29
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,74 @@ What changed in each release, for someone upgrading a workspace. A **printed siz
|
|
|
4
4
|
print (a gear's tip diameter, a tooth's thickness). Each release says whether any printed size moved, and why.
|
|
5
5
|
Releases before this file was started are described in their pull requests on GitHub.
|
|
6
6
|
|
|
7
|
+
## 0.4.0: unused names removed from the mesh drawing; mesh and contact judge a pair at the centre distance given, with its tips and its ring; needs Node 22.13 or later, the version the kit is tested on; a tooth's root stress is read at its surface
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Values the code worked out and never used are gone. No printed size moves, and nothing a design or a check does
|
|
12
|
+
changes.
|
|
13
|
+
|
|
14
|
+
- @rulecad/gears now states Node 22.13 or later in its `engines`, the same lowest Node as every rulecad package, and the
|
|
15
|
+
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 April
|
|
16
|
+
2026, and the kit's packages stated five different lowest versions, some of them too low: on Node 20.6 to 20.9 `cad`
|
|
17
|
+
stopped at start-up with "Unexpected token 'with'", and on Node 22.0 to 22.12 every `cad` command that runs a design
|
|
18
|
+
stops, because the sandbox designs run in cannot start there. npm gave no warning at install for either.
|
|
19
|
+
|
|
20
|
+
Upgrading: on a Node older than 22.13, npm now warns at install that this package needs Node 22.13; install Node 22.13
|
|
21
|
+
or later (24 recommended). Nothing else changes, and no printed size moves.
|
|
22
|
+
|
|
23
|
+
### Already published
|
|
24
|
+
|
|
25
|
+
- The gear-mesh changes listed here (`mesh()` and `contact()` judging a pair at the centre given, and
|
|
26
|
+
`mesh.tipClearance`) are already in @rulecad/gears 0.3.5 as it went out on npm on 2026-11-29, though that version's
|
|
27
|
+
CHANGELOG did not say so (a line there now does): its publish run took the commit merged just after the release
|
|
28
|
+
(#573) in place of the release itself. A workspace already on 0.3.5 has them; this release only records them.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- `mesh(a, b, { centre })` works out the contact ratio, and the working pressure angle it returns, at the centre
|
|
33
|
+
given, not at the one the gears need: 20 teeth on 40 at module 1 set 31 mm apart now fail `mesh.contact` at 0.74
|
|
34
|
+
(they passed at 1.63). Pairs set apart so far that the teeth never meet fail and say so, helical pairs too (a long
|
|
35
|
+
twist no longer makes up for teeth that don't reach), and so do axes so close that the base circles overlap, or at
|
|
36
|
+
no distance at all. A pair off its centre that passed before can now warn or fail.
|
|
37
|
+
- `mesh.centre` read a pinion in a ring the wrong way round: moved out from the ring's centre its teeth go deeper,
|
|
38
|
+
so it is tighter, not looser. It now says so, and a pinion pushed too far out fails.
|
|
39
|
+
- `contact()` fails a pair that never touches as drawn (`mesh.contact`, "the teeth don't touch at ... steps"), instead
|
|
40
|
+
of passing it with "Infinity mm of play"; its `backlash` is then `{ least: null, most: null }`. No finding prints
|
|
41
|
+
Infinity or NaN.
|
|
42
|
+
- `contact()` tests the outlines wherever the teeth can meet (inside both tip circles), not only within 3.5 modules of
|
|
43
|
+
the pitch point, so a pinion fouling its ring further round fails (20 teeth in a ring of 23, 24 or 26).
|
|
44
|
+
- A pinion in a ring is judged by KHK's trochoid interference condition, which honours shift and the centre, in place
|
|
45
|
+
of the rule that a ring needs 10 teeth more than its pinion: 20 in 28 and 52 in 60 now warn (they clear by the
|
|
46
|
+
backlash) instead of failing, and a shifted 12 in 24, which passed, now fails.
|
|
47
|
+
|
|
48
|
+
- `toothStress` read the root's peak stress at its cells' centres, half a cell inside the fillet. It now reads
|
|
49
|
+
`@rulecad/fea`'s surface stress, where the root's peak is: a module 2, 20-tooth PLA pinion 6 mm wide at 1 N m reads
|
|
50
|
+
17.8 MPa where it read 16.6 (7% higher), and the reading moves under 1% from cells a third bigger, where it moved
|
|
51
|
+
9% (`gear.fe.coarse` warned).
|
|
52
|
+
|
|
53
|
+
Upgrading: tooth stresses by finite elements (`gear.fe`) rise by a few percent, so a tooth near the 2× margin can now
|
|
54
|
+
warn. No printed size moves.
|
|
55
|
+
|
|
56
|
+
### Added
|
|
57
|
+
|
|
58
|
+
- `mesh.tipClearance`: the room under the tips where the axes are. Shifted pairs lose it (18 on 18 both shifted a
|
|
59
|
+
whole module dig 0.165 mm into the roots); it fails below none, warns under a tenth of a module, and gives the
|
|
60
|
+
shortened `addendum` for each gear (ISO 21771's (x₁ + x₂ − y) module shortening) in `values.addendum`, reckoned at
|
|
61
|
+
the centre the gears need; tips that dig in because the axes are set too close are told to move the axes instead.
|
|
62
|
+
`mesh()` returns the room as `clearance`.
|
|
63
|
+
|
|
64
|
+
Upgrading: no printed size moves; tips are still drawn full. A shifted pair that `mesh.tipClearance` fails needs the
|
|
65
|
+
addendum it gives on each gear, which shortens the printed tips. Assemblies with gears off their nominal centre, or
|
|
66
|
+
rings close to their pinions, may give new warnings or failures in `cad check`.
|
|
67
|
+
|
|
7
68
|
## 0.3.5: follows @rulecad/fea 0.3.0
|
|
8
69
|
|
|
70
|
+
Also in 0.3.5 as published (added after the release, to put the record straight): the publish run took the commit
|
|
71
|
+
merged just after the release, so 0.3.5 holds #573 too. `mesh()` and `contact()` judge a pair at the centre distance
|
|
72
|
+
given, with its tips and its ring, and `mesh.tipClearance` is new: a pair off its centre that passed can now warn or
|
|
73
|
+
fail. The next release's notes describe it in full.
|
|
74
|
+
|
|
9
75
|
### Changed
|
|
10
76
|
|
|
11
77
|
- Takes @rulecad/fea 0.3.0.
|
package/contact.mjs
CHANGED
|
@@ -5,15 +5,27 @@
|
|
|
5
5
|
// either way and meets nothing has lost contact. Plain 2D geometry: the outlines' edges where the teeth can meet (the
|
|
6
6
|
// lens where each gear's teeth reach inside the other's tip circle: by the pitch point for outer gears, round much of
|
|
7
7
|
// the ring for a pinion close in a ring), tested for crossing.
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
spurProfile,
|
|
10
|
+
internalProfile,
|
|
11
|
+
rackProfile,
|
|
12
|
+
gearModel,
|
|
13
|
+
internalModel,
|
|
14
|
+
rackModel,
|
|
15
|
+
mesh,
|
|
16
|
+
phase,
|
|
17
|
+
rackPhase,
|
|
18
|
+
} from './core.mjs';
|
|
9
19
|
|
|
10
20
|
const DEG = Math.PI / 180;
|
|
11
21
|
const fmt = (x, d = 3) => String(+x.toFixed(d));
|
|
12
22
|
|
|
13
23
|
// Two edges crossing (each strictly through the other)
|
|
14
24
|
function crosses([p, q], [r, s]) {
|
|
15
|
-
const d1 = (s[0] - r[0]) * (p[1] - r[1]) - (s[1] - r[1]) * (p[0] - r[0]),
|
|
16
|
-
|
|
25
|
+
const d1 = (s[0] - r[0]) * (p[1] - r[1]) - (s[1] - r[1]) * (p[0] - r[0]),
|
|
26
|
+
d2 = (s[0] - r[0]) * (q[1] - r[1]) - (s[1] - r[1]) * (q[0] - r[0]);
|
|
27
|
+
const d3 = (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]),
|
|
28
|
+
d4 = (q[0] - p[0]) * (s[1] - p[1]) - (q[1] - p[1]) * (s[0] - p[0]);
|
|
17
29
|
return d1 * d2 < 0 && d3 * d4 < 0;
|
|
18
30
|
}
|
|
19
31
|
// A set of edges filed in square cells of side h, so each edge of the other set is tested only against those near it
|
|
@@ -24,8 +36,10 @@ function filed(A, h) {
|
|
|
24
36
|
const [p, q] = e;
|
|
25
37
|
for (let i = Math.floor(Math.min(p[0], q[0]) / h); i <= Math.floor(Math.max(p[0], q[0]) / h); i++) {
|
|
26
38
|
for (let j = Math.floor(Math.min(p[1], q[1]) / h); j <= Math.floor(Math.max(p[1], q[1]) / h); j++) {
|
|
27
|
-
const k = i * 65536 + j,
|
|
28
|
-
|
|
39
|
+
const k = i * 65536 + j,
|
|
40
|
+
list = cells.get(k);
|
|
41
|
+
if (list) list.push(e);
|
|
42
|
+
else cells.set(k, [e]);
|
|
29
43
|
}
|
|
30
44
|
}
|
|
31
45
|
}
|
|
@@ -42,9 +56,21 @@ function filed(A, h) {
|
|
|
42
56
|
return false;
|
|
43
57
|
};
|
|
44
58
|
}
|
|
45
|
-
const turn = (pts, a, [cx, cy] = [0, 0], [dx, dy] = [0, 0]) => {
|
|
59
|
+
const turn = (pts, a, [cx, cy] = [0, 0], [dx, dy] = [0, 0]) => {
|
|
60
|
+
const c = Math.cos(a),
|
|
61
|
+
s = Math.sin(a);
|
|
62
|
+
return pts.map(([x, y]) => [x * c - y * s + cx + dx, x * s + y * c + cy + dy]);
|
|
63
|
+
};
|
|
46
64
|
// Only the loop's edges with an end where the mate's teeth can reach (the rest never meet)
|
|
47
|
-
const edgesWhere = (pts, by) => {
|
|
65
|
+
const edgesWhere = (pts, by) => {
|
|
66
|
+
const out = [];
|
|
67
|
+
for (let i = 0; i < pts.length; i++) {
|
|
68
|
+
const p = pts[i],
|
|
69
|
+
q = pts[(i + 1) % pts.length];
|
|
70
|
+
if (by(p) || by(q)) out.push([p, q]);
|
|
71
|
+
}
|
|
72
|
+
return out;
|
|
73
|
+
};
|
|
48
74
|
|
|
49
75
|
/**
|
|
50
76
|
* The mesh of a pair as drawn: backlash, transmission error and interference across one pitch of the driver.
|
|
@@ -54,58 +80,123 @@ const edgesWhere = (pts, by) => { const out = []; for (let i = 0; i < pts.length
|
|
|
54
80
|
*/
|
|
55
81
|
export function contact(a, b, { centre, steps = 24 } = {}) {
|
|
56
82
|
const kind = b.kind ?? 'external';
|
|
57
|
-
const ga = gearModel(a),
|
|
58
|
-
|
|
83
|
+
const ga = gearModel(a),
|
|
84
|
+
gb = kind === 'internal' ? internalModel(b) : kind === 'rack' ? rackModel(b) : gearModel(b);
|
|
85
|
+
const m = mesh(ga, gb, centre === undefined ? {} : { centre }),
|
|
86
|
+
c = centre ?? m.centre,
|
|
87
|
+
mod = ga.module;
|
|
59
88
|
const A = spurProfile(a).loops[0];
|
|
60
|
-
const B =
|
|
89
|
+
const B =
|
|
90
|
+
kind === 'internal'
|
|
91
|
+
? internalProfile(b).loops[1]
|
|
92
|
+
: kind === 'rack'
|
|
93
|
+
? rackProfile(b).loops[0]
|
|
94
|
+
: spurProfile(b).loops[0];
|
|
61
95
|
// where the driven sits, and how it moves: an angle (degrees) about its centre, or along the rack (mm)
|
|
62
|
-
const per = kind === 'rack' ? (Math.PI * ga.pitch) / 360 : m.ratio,
|
|
96
|
+
const per = kind === 'rack' ? (Math.PI * ga.pitch) / 360 : m.ratio,
|
|
97
|
+
r2 = kind === 'rack' ? null : gb.pitch / 2;
|
|
63
98
|
const base = kind === 'rack' ? rackPhase(ga, 0) : phase(ga, gb, kind === 'internal' ? 180 : 0);
|
|
64
99
|
const O2 = kind === 'internal' ? [-c, 0] : kind === 'rack' ? null : [c, 0];
|
|
65
100
|
// Where the teeth can meet: the driver's edges inside the driven's tip circle (outside it, for a ring; under the
|
|
66
101
|
// rack's tip line), the driven's inside the driver's tip circle, each with a little to spare for the edges' length.
|
|
67
102
|
// (It was once a circle of 3.5 modules round the pitch point, which missed a pinion fouling its ring further round.)
|
|
68
|
-
const O1 = kind === 'rack' ? [0, c] : [0, 0],
|
|
103
|
+
const O1 = kind === 'rack' ? [0, c] : [0, 0],
|
|
104
|
+
spare = 0.25 * mod,
|
|
105
|
+
ra1 = ga.tip / 2 + spare;
|
|
69
106
|
const d2 = ([x, y], [px, py]) => (x - px) ** 2 + (y - py) ** 2;
|
|
70
|
-
const inDriven =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
107
|
+
const inDriven =
|
|
108
|
+
kind === 'rack'
|
|
109
|
+
? ([, y]) => y < gb.tipLine + spare
|
|
110
|
+
: kind === 'internal'
|
|
111
|
+
? (p) => d2(p, O2) > (gb.tip / 2 - spare) ** 2
|
|
112
|
+
: (p) => d2(p, O2) < (gb.tip / 2 + spare) ** 2;
|
|
113
|
+
const inDriver = (p) => d2(p, O1) < ra1 * ra1,
|
|
114
|
+
cell = 0.5 * mod;
|
|
115
|
+
const drivenAt = (deg, nudge) =>
|
|
116
|
+
kind === 'rack'
|
|
117
|
+
? B.map(([x, y]) => [x + per * deg + base + nudge - Math.PI * mod * Math.round(gb.teeth / 2), y]) // the rack under the pinion, its middle under the pitch point
|
|
118
|
+
: turn(B, (m.ratio * deg + base + nudge) * DEG, O2);
|
|
77
119
|
const driverAt = (deg) => turn(A, deg * DEG, O1);
|
|
78
120
|
// the turn (degrees, or mm for a rack) each way from the ratio's place to where the outlines first meet
|
|
79
|
-
const span = kind === 'rack' ? Math.PI * mod / 2 : 180 / gb.teeth;
|
|
121
|
+
const span = kind === 'rack' ? (Math.PI * mod) / 2 : 180 / gb.teeth;
|
|
80
122
|
const meet = (deg, dir) => {
|
|
81
|
-
const D = filed(edgesWhere(driverAt(deg), inDriven), cell),
|
|
123
|
+
const D = filed(edgesWhere(driverAt(deg), inDriven), cell),
|
|
124
|
+
hits = (x) => D(edgesWhere(drivenAt(deg, dir * x), inDriver));
|
|
82
125
|
if (!hits(span)) return Infinity;
|
|
83
|
-
let lo = 0,
|
|
84
|
-
|
|
126
|
+
let lo = 0,
|
|
127
|
+
hi = span;
|
|
128
|
+
for (let i = 0; i < 40; i++) {
|
|
129
|
+
const mid = (lo + hi) / 2;
|
|
130
|
+
if (hits(mid)) hi = mid;
|
|
131
|
+
else lo = mid;
|
|
132
|
+
}
|
|
85
133
|
return lo;
|
|
86
134
|
};
|
|
87
135
|
const rows = [];
|
|
88
136
|
for (let i = 0; i < steps; i++) {
|
|
89
|
-
const deg = (i * 360) / ga.teeth / steps,
|
|
137
|
+
const deg = (i * 360) / ga.teeth / steps,
|
|
138
|
+
D = filed(edgesWhere(driverAt(deg), inDriven), cell);
|
|
90
139
|
const clash = D(edgesWhere(drivenAt(deg, 0), inDriver));
|
|
91
|
-
if (clash) {
|
|
140
|
+
if (clash) {
|
|
141
|
+
rows.push({ angle: deg, interferes: true });
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
92
144
|
// the driven pushed on (it lags until its flank meets the driver's: the driver turning +, the driven its way)
|
|
93
|
-
const ahead = meet(deg, Math.sign(per)),
|
|
145
|
+
const ahead = meet(deg, Math.sign(per)),
|
|
146
|
+
behind = meet(deg, -Math.sign(per));
|
|
94
147
|
// half a tooth either way and nothing met: no tooth is there to push (or to hold it back)
|
|
95
|
-
if (!Number.isFinite(ahead) || !Number.isFinite(behind)) {
|
|
148
|
+
if (!Number.isFinite(ahead) || !Number.isFinite(behind)) {
|
|
149
|
+
rows.push({ angle: deg, apart: true });
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
96
152
|
const toMm = (x) => (kind === 'rack' ? x : x * DEG * r2);
|
|
97
153
|
rows.push({ angle: deg, backlash: toMm(ahead + behind), error: toMm(behind) });
|
|
98
154
|
}
|
|
99
|
-
const out = [],
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
155
|
+
const out = [],
|
|
156
|
+
f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
157
|
+
const bad = rows.filter((x) => x.interferes),
|
|
158
|
+
apart = rows.filter((x) => x.apart);
|
|
159
|
+
const ok = rows.filter((x) => !x.interferes && !x.apart),
|
|
160
|
+
bl = ok.map((x) => x.backlash),
|
|
161
|
+
te = ok.map((x) => x.error);
|
|
162
|
+
const least = ok.length ? Math.min(...bl) : null,
|
|
163
|
+
most = ok.length ? Math.max(...bl) : null,
|
|
164
|
+
swing = te.length ? Math.max(...te) - Math.min(...te) : 0;
|
|
165
|
+
if (bad.length)
|
|
166
|
+
f(
|
|
167
|
+
'fail',
|
|
168
|
+
`the teeth cross where the ratio puts them at ${bad.length} of ${steps} steps (from ${fmt(bad[0].angle, 2)}° of the driver): they interfere, and jam`,
|
|
169
|
+
'mesh.interference',
|
|
170
|
+
{ at: bad.map((x) => x.angle) },
|
|
171
|
+
);
|
|
172
|
+
if (apart.length)
|
|
173
|
+
f(
|
|
174
|
+
'fail',
|
|
175
|
+
`the teeth don't touch at ${apart.length} of ${steps} steps (from ${fmt(apart[0].angle, 2)}° of the driver): turned half a tooth either way, the driven meets nothing, so at the ${fmt(c)} mm centre${centre !== undefined && Math.abs(c - m.centre) > 0.005 ? ` (${fmt(m.centre)} mm is where they mesh)` : ''} they lose contact and slip: bring the axes closer`,
|
|
176
|
+
'mesh.contact',
|
|
177
|
+
{ at: apart.map((x) => x.angle), centre: c },
|
|
178
|
+
);
|
|
105
179
|
if (ok.length) {
|
|
106
|
-
if (least < 0.02)
|
|
107
|
-
|
|
108
|
-
|
|
180
|
+
if (least < 0.02)
|
|
181
|
+
f(
|
|
182
|
+
'warn',
|
|
183
|
+
`as drawn, the play falls to ${fmt(least)} mm: printed teeth that come out a little fat will bind`,
|
|
184
|
+
'mesh.backlash',
|
|
185
|
+
{ least, most },
|
|
186
|
+
);
|
|
187
|
+
else
|
|
188
|
+
f(
|
|
189
|
+
'pass',
|
|
190
|
+
`as drawn, ${fmt(least)}${fmt(most) !== fmt(least) ? ` to ${fmt(most)}` : ''} mm of play at the pitch circle (${fmt(m.backlash)} mm reckoned)`,
|
|
191
|
+
'mesh.backlash',
|
|
192
|
+
{ least, most },
|
|
193
|
+
);
|
|
194
|
+
f(
|
|
195
|
+
'info',
|
|
196
|
+
`transmission error ${fmt(swing * 1000, 0)} µm across a tooth, as drawn (outlines of ${A.length / ga.teeth} points a tooth)`,
|
|
197
|
+
'mesh.error',
|
|
198
|
+
{ swing },
|
|
199
|
+
);
|
|
109
200
|
}
|
|
110
201
|
// (least and most are null when no step had the teeth touching both ways)
|
|
111
202
|
return { rows, backlash: { least, most }, error: swing, reckoned: m.backlash, findings: out };
|