@rulecad/gears 0.3.4 → 0.3.5

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 CHANGED
@@ -4,6 +4,12 @@ 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.3.5: follows @rulecad/fea 0.3.0
8
+
9
+ ### Changed
10
+
11
+ - Takes @rulecad/fea 0.3.0.
12
+
7
13
  ## 0.3.4: the compound planetary printed in place (#162)
8
14
 
9
15
  ### Added
package/README.md CHANGED
@@ -24,7 +24,7 @@ const solid = spur({ module: 1, teeth: 18, width: 6, bore: 5 }); // a JSCAD soli
24
24
 
25
25
  ```text
26
26
  30 -0.4286 1.63 0.15
27
- pass mesh.contact, pass mesh.centre
27
+ pass mesh.contact, pass mesh.tipClearance, pass mesh.centre
28
28
  4.286
29
29
  18 16.914 20 15.5
30
30
  pass: module 1: 3.6 lines across a tooth at its pitch circle
@@ -75,14 +75,36 @@ What every gear takes:
75
75
  - **`centre`**: how far apart the axes must be (for a rack, the pinion's axis above the rack's pitch line). Shifted
76
76
  gears move apart by their working pressure angle.
77
77
  - **`ratio`**: turns of b for each turn of a, negative when they turn opposite ways. For a rack, mm of travel a turn.
78
- - **`contact`**: the contact ratio, how many pairs of teeth share the load on average. Under 1 the drive jumps; under
79
- 1.2 it is rough.
78
+ - **`contact`**: the contact ratio, how many pairs of teeth share the load on average, where the axes are: at the
79
+ `centre` you gave, or else at the one they need. Under 1 the drive jumps; under 1.2 it is rough. Apart from their
80
+ place the gears roll at a new working pressure angle (cos α_w = (r_b1 ± r_b2) / a) and the teeth overlap less: 20
81
+ teeth on 40 at module 1 share 1.63 pairs at their 30 mm, 1.17 at 30.5 mm and 0.74 at 31 mm, where the drive jumps.
82
+ `pressureAngle` is the working angle at that centre too. A pair whose teeth don't reach across fails, whatever a
83
+ helical's twist would add, and so do axes so close that the base circles overlap.
84
+ - **`clearance`**: the room under the tips, in mm, at that centre (0.25 module as drawn).
80
85
  - **`backlash`**: the play, with the centre you gave.
81
86
  - **`overlap`** and **`thrust`**: for helical gears, with `width` given, how much the twist adds to the contact ratio, and the push along the axis for each newton driven (none for a herringbone).
82
- - **`findings`**: `mesh.contact`, `mesh.centre` (axes closer than the gears need eat their backlash, 2 Δa tan α of it, and past
83
- it jam the teeth; too far apart, they knock), `mesh.module` and
84
- `mesh.pressure` (gears that can't mesh), `mesh.interference` (a ring too near its pinion's size), `mesh.helix` (helical
85
- gears that cross: outer gears that mesh are of opposite hands; a pinion and its ring or rack, of the same hand).
87
+ - **`findings`**: `mesh.contact` (each finding names the centre when you gave one off the gears' own), `mesh.centre`
88
+ (axes closer than the gears need eat their backlash, 2 Δa tan α of it, and past it jam the teeth; too far apart,
89
+ they knock), `mesh.tipClearance`, `mesh.module` and `mesh.pressure` (gears that can't mesh), `mesh.interference`
90
+ (a pinion's tips fouling its ring's), `mesh.helix` (helical gears that cross: outer gears that mesh are of opposite
91
+ hands; a pinion and its ring or rack, of the same hand).
92
+
93
+ **Tips of shifted gears.** Profile shift pushes a gear's tips out further than it pushes the pair apart, so two
94
+ shifted gears lose the room under their tips they were drawn with: 18 teeth on 18, both shifted a whole module, have
95
+ none, and the tips dig 0.165 mm into the roots. ISO 21771 and KHK shorten each tip by (x₁ + x₂ − y) modules, y being
96
+ how far the shift moved the centre. Each gear is drawn on its own, without its mate, so its tips are drawn full;
97
+ `mesh.tipClearance` fails a pair whose tips reach the mate's roots, warns under a tenth of a module of room, and says
98
+ the `addendum` that gives the room back (it is in the finding's `values.addendum`, the first gear's and the
99
+ second's, reckoned at the centre the gears need: tips that dig in only because the axes are set too close are told to
100
+ move the axes). For KHK's worked pair (module 3, 12 and 24 teeth shifted 0.6 and 0.36) that is 0.873 on both, which gives
101
+ the tips KHK lists, 44.84 and 79.40 mm.
102
+
103
+ **A pinion in a ring.** As each pinion tooth leaves the ring's space its tip swings out past the corner of the ring's
104
+ tooth. `mesh.interference` tests that by KHK's trochoid condition, which honours the shift and the centre, and
105
+ allows each flank a quarter of each gear's backlash: 20 teeth in a ring of 26 or 27 fail, 28 clear by the backlash
106
+ alone (a warn), 30 clear outright. It no longer goes by the number of teeth between them, which failed rings that
107
+ clear and passed shifted pinions that don't (12 shifted 0.3 in 24).
86
108
 
87
109
  `phase(a, b, angle)` is the turn that puts a tooth of a in a space of b: b's angle is `ratio × a's angle + phase`,
88
110
  with `angle` the direction from a's centre to b's. `rackPhase(pinion, at)` does the same for a rack.
@@ -166,7 +188,13 @@ and at each step turns the driven gear each way until its outline meets the driv
166
188
  - **backlash**: the turn between the two meetings, as play at the pitch circle (`mesh.backlash`, a warn when it falls
167
189
  under 0.02 mm);
168
190
  - **transmission error**: how far the driven gear's forward meeting wanders across a tooth (`mesh.error`);
169
- - **interference**: steps where the outlines already cross where the ratio puts them (`mesh.interference`).
191
+ - **interference**: steps where the outlines already cross where the ratio puts them (`mesh.interference`);
192
+ - **lost contact**: steps where the driven gear turns half a tooth either way without meeting the driver, so the axes
193
+ are too far apart for the teeth to drive (`mesh.contact`, a fail). The backlash is then left out, and `backlash` is
194
+ `{ least: null, most: null }` if no step touched.
195
+
196
+ It tests every edge where the teeth can meet: inside both tip circles, which for outer gears is close round the pitch
197
+ point and for a pinion in a ring can be much of the way round.
170
198
 
171
199
  `a` and `b` are the parameters the models take; `b.kind` is `'internal'` for a ring or `'rack'` for a rack. For 18
172
200
  teeth on 30 at module 1 it measures 0.150 to 0.152 mm of play against the 0.15 mm drawn, and 1 µm of transmission
@@ -238,14 +266,15 @@ a point.
238
266
  | Undercut | none when z sin²α / 2 ≥ h_a − x (17 teeth at 20°) | ISO 21771; KHK |
239
267
  | Working pressure angle | inv α_w = inv α + 2 tan α (x₁ + x₂) / (z₁ + z₂) | ISO 21771 |
240
268
  | Centre distance | a = m (z₁ + z₂) cos α / 2 cos α_w; a ring: z₂ − z₁ | ISO 21771 |
241
- | Contact ratio | (√(r_a1² − r_b1²) + √(r_a2² − r_b2²) − a sin α_w) / (π m cos α) | Dudley (1984); KHK |
242
- | Rack contact | (√(r_a² − r_b²) − r sin α + m (h_a − x) / sin α) / (π m cos α) | KHK |
269
+ | Contact ratio | (√(r_a1² − r_b1²) + √(r_a2² − r_b2²) − a sin α_w) / (π m cos α), at the centre a used, cos α_w = (r_b1 + r_b2) / a | Dudley (1984); KHK |
270
+ | Rack contact | (√(r_a² − r_b²) − r sin α + (m h_a − (a − r)) / sin α) / (π m cos α), a the pinion's axis above the pitch line | KHK |
271
+ | Room under the tips | a − r_a1 − r_f2 (a ring: r_f2 − a − r_a1 and r_a2 − a − r_f1); shifted tips shortened by (x₁ + x₂ − y) m | ISO 21771; KHK |
243
272
  | Root fillet | 0.38 m | ISO 53 profile A |
244
273
  | Helical twist | the profile turns z tan β / r up the width | ISO 21771 (transverse module) |
245
274
  | Overlap ratio | ε_β = b tan β / π m (each half of a herringbone on its own) | ISO 21771 |
246
275
  | Thrust | F_a = F_t tan β | Dudley (1984) |
247
276
  | Flank lean at the tip | tan β_a = tan β · r_a / r | ISO 21771 |
248
- | Ring and pinion | at least 10 teeth apart (12 to be safe) at 20° | KHK, internal gears |
277
+ | Ring and pinion (trochoid interference) | θ₁ z₁/z₂ + inv α_w − inv α_a2 ≥ θ₂; θ₁ = acos((r_a2² − r_a1² − a²) / 2a r_a1) + inv α_a1 − inv α_w, θ₂ = acos((a² + r_a2² − r_a1²) / 2a r_a2) | KHK, internal gears |
249
278
  | Planetary ratio | (ω_s − ω_c) / (ω_r − ω_c) = −R / S; ring held, sun in: 1 + R / S | Willis; Dudley (1984), ch. 3 |
250
279
  | Planetary assembly | R = S + 2P; (S + R) / n whole; 2a sin(π / n) > d_a,planet | KHK, planetary gears |
251
280
  | Compound play at the output | j_s \|1 − r2/r1\| / 2 + j_r1 (1 + r2/r1) / 2 + j_r2, over the output ring's pitch radius | The three contacts' slips along their pitch circles, planets free of a carrier (this package) |
package/contact.d.mts CHANGED
@@ -13,6 +13,13 @@ export function contact(a: object, b: object & {
13
13
  rows: ({
14
14
  angle: number;
15
15
  interferes: boolean;
16
+ apart?: undefined;
17
+ backlash?: undefined;
18
+ error?: undefined;
19
+ } | {
20
+ angle: number;
21
+ apart: boolean;
22
+ interferes?: undefined;
16
23
  backlash?: undefined;
17
24
  error?: undefined;
18
25
  } | {
@@ -20,6 +27,7 @@ export function contact(a: object, b: object & {
20
27
  backlash: any;
21
28
  error: any;
22
29
  interferes?: undefined;
30
+ apart?: undefined;
23
31
  })[];
24
32
  backlash: {
25
33
  least: number;
package/contact.mjs CHANGED
@@ -1,29 +1,50 @@
1
1
  // The mesh measured, not reckoned: the drawn teeth turned through a pitch, and at each step the driven gear turned
2
2
  // each way until its outline meets the driver's. The turn between the two meetings is the backlash as drawn (with the
3
3
  // real fillets, rounds and centre distance); how far the forward meeting is from where the ratio puts it is the
4
- // transmission error; outlines that cross where the ratio puts them interfere. Plain 2D geometry: the outlines'
5
- // edges near the pitch point, tested for crossing.
4
+ // transmission error; outlines that cross where the ratio puts them interfere; a driven gear that turns half a tooth
5
+ // either way and meets nothing has lost contact. Plain 2D geometry: the outlines' edges where the teeth can meet (the
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
+ // the ring for a pinion close in a ring), tested for crossing.
6
8
  import { spurProfile, internalProfile, rackProfile, gearModel, internalModel, rackModel, mesh, phase, rackPhase } from './core.mjs';
7
9
 
8
10
  const DEG = Math.PI / 180;
9
11
  const fmt = (x, d = 3) => String(+x.toFixed(d));
10
12
 
11
- // Do two sets of edges cross anywhere? Edge against edge, with a box test first
12
- function cross(A, B) {
13
- for (const [p, q] of A) {
14
- const x0 = Math.min(p[0], q[0]), x1 = Math.max(p[0], q[0]), y0 = Math.min(p[1], q[1]), y1 = Math.max(p[1], q[1]);
15
- for (const [r, s] of B) {
16
- if (Math.max(r[0], s[0]) < x0 || Math.min(r[0], s[0]) > x1 || Math.max(r[1], s[1]) < y0 || Math.min(r[1], s[1]) > y1) continue;
17
- const d1 = (s[0] - r[0]) * (p[1] - r[1]) - (s[1] - r[1]) * (p[0] - r[0]), d2 = (s[0] - r[0]) * (q[1] - r[1]) - (s[1] - r[1]) * (q[0] - r[0]);
18
- const d3 = (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]), d4 = (q[0] - p[0]) * (s[1] - p[1]) - (q[1] - p[1]) * (s[0] - p[0]);
19
- if (d1 * d2 < 0 && d3 * d4 < 0) return true;
13
+ // Two edges crossing (each strictly through the other)
14
+ 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]), d2 = (s[0] - r[0]) * (q[1] - r[1]) - (s[1] - r[1]) * (q[0] - r[0]);
16
+ const d3 = (q[0] - p[0]) * (r[1] - p[1]) - (q[1] - p[1]) * (r[0] - p[0]), d4 = (q[0] - p[0]) * (s[1] - p[1]) - (q[1] - p[1]) * (s[0] - p[0]);
17
+ return d1 * d2 < 0 && d3 * d4 < 0;
18
+ }
19
+ // 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
20
+ // (a pinion close in a ring meets it round much of its turn, and every edge against every edge is slow)
21
+ function filed(A, h) {
22
+ const cells = new Map();
23
+ for (const e of A) {
24
+ const [p, q] = e;
25
+ for (let i = Math.floor(Math.min(p[0], q[0]) / h); i <= Math.floor(Math.max(p[0], q[0]) / h); i++) {
26
+ 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, list = cells.get(k);
28
+ if (list) list.push(e); else cells.set(k, [e]);
29
+ }
20
30
  }
21
31
  }
22
- return false;
32
+ return (B) => {
33
+ for (const e of B) {
34
+ const [r, s] = e;
35
+ for (let i = Math.floor(Math.min(r[0], s[0]) / h); i <= Math.floor(Math.max(r[0], s[0]) / h); i++) {
36
+ for (let j = Math.floor(Math.min(r[1], s[1]) / h); j <= Math.floor(Math.max(r[1], s[1]) / h); j++) {
37
+ const list = cells.get(i * 65536 + j);
38
+ if (list) for (const d of list) if (crosses(d, e)) return true;
39
+ }
40
+ }
41
+ }
42
+ return false;
43
+ };
23
44
  }
24
45
  const turn = (pts, a, [cx, cy] = [0, 0], [dx, dy] = [0, 0]) => { const c = Math.cos(a), s = Math.sin(a); return pts.map(([x, y]) => [x * c - y * s + cx + dx, x * s + y * c + cy + dy]); };
25
- // Only the loop's edges near a point (the far teeth never meet)
26
- const near = (pts, [px, py], r) => { const by = ([x, y]) => (x - px) ** 2 + (y - py) ** 2 < r * r, out = []; for (let i = 0; i < pts.length; i++) { const p = pts[i], q = pts[(i + 1) % pts.length]; if (by(p) || by(q)) out.push([p, q]); } return out; };
46
+ // Only the loop's edges with an end where the mate's teeth can reach (the rest never meet)
47
+ const edgesWhere = (pts, by) => { const out = []; for (let i = 0; i < pts.length; i++) { const p = pts[i], q = pts[(i + 1) % pts.length]; if (by(p) || by(q)) out.push([p, q]); } return out; };
27
48
 
28
49
  /**
29
50
  * The mesh of a pair as drawn: backlash, transmission error and interference across one pitch of the driver.
@@ -41,39 +62,51 @@ export function contact(a, b, { centre, steps = 24 } = {}) {
41
62
  const per = kind === 'rack' ? (Math.PI * ga.pitch) / 360 : m.ratio, r2 = kind === 'rack' ? null : gb.pitch / 2;
42
63
  const base = kind === 'rack' ? rackPhase(ga, 0) : phase(ga, gb, kind === 'internal' ? 180 : 0);
43
64
  const O2 = kind === 'internal' ? [-c, 0] : kind === 'rack' ? null : [c, 0];
44
- const P = kind === 'internal' ? [ga.pitch / 2, 0] : kind === 'rack' ? [0, c - ga.pitch / 2] : [ga.pitch / 2, 0], reach = 3.5 * mod;
65
+ // Where the teeth can meet: the driver's edges inside the driven's tip circle (outside it, for a ring; under the
66
+ // rack's tip line), the driven's inside the driver's tip circle, each with a little to spare for the edges' length.
67
+ // (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], spare = 0.25 * mod, ra1 = ga.tip / 2 + spare;
69
+ const d2 = ([x, y], [px, py]) => (x - px) ** 2 + (y - py) ** 2;
70
+ const inDriven = kind === 'rack' ? ([, y]) => y < gb.tipLine + spare
71
+ : kind === 'internal' ? (p) => d2(p, O2) > (gb.tip / 2 - spare) ** 2
72
+ : (p) => d2(p, O2) < (gb.tip / 2 + spare) ** 2;
73
+ const inDriver = (p) => d2(p, O1) < ra1 * ra1, cell = 0.5 * mod;
45
74
  const drivenAt = (deg, nudge) => kind === 'rack'
46
75
  ? 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
47
76
  : turn(B, (m.ratio * deg + base + nudge) * DEG, O2);
48
- const driverAt = (deg) => turn(A, deg * DEG, kind === 'rack' ? [0, c] : [0, 0]);
77
+ const driverAt = (deg) => turn(A, deg * DEG, O1);
49
78
  // the turn (degrees, or mm for a rack) each way from the ratio's place to where the outlines first meet
50
79
  const span = kind === 'rack' ? Math.PI * mod / 2 : 180 / gb.teeth;
51
80
  const meet = (deg, dir) => {
52
- const D = near(driverAt(deg), P, reach), crosses = (x) => cross(D, near(drivenAt(deg, dir * x), P, reach));
53
- if (!crosses(span)) return Infinity;
81
+ const D = filed(edgesWhere(driverAt(deg), inDriven), cell), hits = (x) => D(edgesWhere(drivenAt(deg, dir * x), inDriver));
82
+ if (!hits(span)) return Infinity;
54
83
  let lo = 0, hi = span;
55
- for (let i = 0; i < 40; i++) { const mid = (lo + hi) / 2; if (crosses(mid)) hi = mid; else lo = mid; }
84
+ for (let i = 0; i < 40; i++) { const mid = (lo + hi) / 2; if (hits(mid)) hi = mid; else lo = mid; }
56
85
  return lo;
57
86
  };
58
87
  const rows = [];
59
88
  for (let i = 0; i < steps; i++) {
60
- const deg = (i * 360) / ga.teeth / steps, D = near(driverAt(deg), P, reach);
61
- const clash = cross(D, near(drivenAt(deg, 0), P, reach));
89
+ const deg = (i * 360) / ga.teeth / steps, D = filed(edgesWhere(driverAt(deg), inDriven), cell);
90
+ const clash = D(edgesWhere(drivenAt(deg, 0), inDriver));
62
91
  if (clash) { rows.push({ angle: deg, interferes: true }); continue; }
63
92
  // the driven pushed on (it lags until its flank meets the driver's: the driver turning +, the driven its way)
64
93
  const ahead = meet(deg, Math.sign(per)), behind = meet(deg, -Math.sign(per));
94
+ // 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)) { rows.push({ angle: deg, apart: true }); continue; }
65
96
  const toMm = (x) => (kind === 'rack' ? x : x * DEG * r2);
66
97
  rows.push({ angle: deg, backlash: toMm(ahead + behind), error: toMm(behind) });
67
98
  }
68
99
  const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
69
- const bad = rows.filter((x) => x.interferes);
70
- const ok = rows.filter((x) => !x.interferes), bl = ok.map((x) => x.backlash), te = ok.map((x) => x.error);
71
- const least = Math.min(...bl), most = Math.max(...bl), swing = te.length ? Math.max(...te) - Math.min(...te) : 0;
100
+ const bad = rows.filter((x) => x.interferes), apart = rows.filter((x) => x.apart);
101
+ const ok = rows.filter((x) => !x.interferes && !x.apart), bl = ok.map((x) => x.backlash), te = ok.map((x) => x.error);
102
+ const least = ok.length ? Math.min(...bl) : null, most = ok.length ? Math.max(...bl) : null, swing = te.length ? Math.max(...te) - Math.min(...te) : 0;
72
103
  if (bad.length) f('fail', `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`, 'mesh.interference', { at: bad.map((x) => x.angle) });
104
+ if (apart.length) f('fail', `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`, 'mesh.contact', { at: apart.map((x) => x.angle), centre: c });
73
105
  if (ok.length) {
74
106
  if (least < 0.02) f('warn', `as drawn, the play falls to ${fmt(least)} mm: printed teeth that come out a little fat will bind`, 'mesh.backlash', { least, most });
75
107
  else f('pass', `as drawn, ${fmt(least)}${fmt(most) !== fmt(least) ? ` to ${fmt(most)}` : ''} mm of play at the pitch circle (${fmt(m.backlash)} mm reckoned)`, 'mesh.backlash', { least, most });
76
108
  f('info', `transmission error ${fmt(swing * 1000, 0)} µm across a tooth, as drawn (outlines of ${A.length / ga.teeth} points a tooth)`, 'mesh.error', { swing });
77
109
  }
110
+ // (least and most are null when no step had the teeth touching both ways)
78
111
  return { rows, backlash: { least, most }, error: swing, reckoned: m.backlash, findings: out };
79
112
  }
package/core.mjs CHANGED
@@ -443,55 +443,114 @@ export function mesh(a, b, { centre, width } = {}) {
443
443
  if ((a.hand === b.hand) !== same) f('fail', `both are ${a.hand}-handed: ${same ? `a pinion and its ${b.kind === 'rack' ? 'rack' : 'ring'} are of the same hand` : 'outer gears that mesh are of opposite hands'}`, 'mesh.helix');
444
444
  if (!!a.herringbone !== !!b.herringbone) f('fail', 'a herringbone meshes only with a herringbone', 'mesh.helix');
445
445
  }
446
- const ra1 = a.tip / 2, rb1 = a.base / 2, r1 = a.pitch / 2;
447
- let need, ratio, contact, aw = al;
446
+ if (centre !== undefined && !isNum(centre)) throw new Error(`mesh: centre is a distance in mm (got ${shown(centre)})`);
447
+ const ra1 = a.tip / 2, rb1 = a.base / 2, r1 = a.pitch / 2, rf1 = a.root / 2;
448
+ let need, ratio, aw = al;
448
449
  if (b.kind === 'external') {
449
450
  aw = working(al, a.shift + b.shift, a.teeth + b.teeth);
450
451
  need = ((a.teeth + b.teeth) * m * Math.cos(al)) / (2 * Math.cos(aw));
451
452
  ratio = -a.teeth / b.teeth;
452
- contact = (Math.sqrt(ra1 ** 2 - rb1 ** 2) + Math.sqrt((b.tip / 2) ** 2 - (b.base / 2) ** 2) - need * Math.sin(aw)) / pb;
453
453
  } else if (b.kind === 'internal') {
454
454
  if (b.teeth <= a.teeth) throw new Error(`mesh: a ring of ${b.teeth} teeth can't hold a pinion of ${a.teeth}`);
455
455
  aw = working(al, b.shift - a.shift, b.teeth - a.teeth);
456
456
  need = ((b.teeth - a.teeth) * m * Math.cos(al)) / (2 * Math.cos(aw));
457
457
  ratio = a.teeth / b.teeth;
458
- const rb2 = b.base / 2, ra2 = Math.max(b.tip / 2, rb2); // (a ring's tip under its base circle doesn't roll)
459
- contact = (Math.sqrt(ra1 ** 2 - rb1 ** 2) - Math.sqrt(ra2 ** 2 - rb2 ** 2) + need * Math.sin(aw)) / pb;
460
- const gap = b.teeth - a.teeth;
461
- // Rule of thumb (KHK, Gear Technical Reference, internal gears): with full-depth 20° teeth and no shift, a ring
462
- // under about 10 teeth more than its pinion fouls it (involute or trochoid interference); 12 is the safe side
463
- if (gap < 10) f('fail', `the ring has ${gap} teeth more than its pinion: under 10, their tips foul each other (interference); more teeth on the ring, or fewer on the pinion`, 'mesh.interference', { gap });
464
- else if (gap < 12) f('warn', `the ring has ${gap} teeth more than its pinion: near the limit of 10 where tips foul; check it by contact`, 'mesh.interference', { gap });
465
458
  } else { // a rack
466
459
  need = r1 + a.shift * m; // the pinion's centre above the rack's pitch line
467
460
  ratio = Math.PI * a.pitch; // mm a turn
468
- contact = (Math.sqrt(ra1 ** 2 - rb1 ** 2) - r1 * Math.sin(al) + (m * (b.rack.addendum - a.shift)) / Math.sin(al)) / pb;
469
461
  }
462
+ // Everything from here is judged where the axes are: at the centre given, or else at the one they need. Apart from
463
+ // their nominal place the gears roll on new pitch circles at a new working pressure angle, cos αw = (rb1 ± rb2) / a
464
+ // (the line of action stays tangent to both base circles), and the path of contact, cut by the two tip circles,
465
+ // shortens: a 20 and 40 tooth pair at module 1 has a contact ratio of 1.63 at its 30 mm and 0.74 at 31 mm. (A rack's
466
+ // flanks keep their slope: moving the pinion off it shortens the rack's share of the path instead.)
467
+ const at = centre ?? need, given = centre !== undefined && Math.abs(centre - need) > 0.005;
468
+ let awAt = al, path;
469
+ // (two outer gears closer than their base circles' radii together, or axes at or past each other, can't roll at all)
470
+ const crowded = !(at > 0) || (b.kind === 'external' && at < rb1 + b.base / 2);
471
+ if (b.kind === 'external') {
472
+ awAt = Math.acos(Math.min(1, (rb1 + b.base / 2) / at));
473
+ path = Math.sqrt(ra1 ** 2 - rb1 ** 2) + Math.sqrt((b.tip / 2) ** 2 - (b.base / 2) ** 2) - at * Math.sin(awAt);
474
+ } else if (b.kind === 'internal') {
475
+ const rb2 = b.base / 2, ra2 = Math.max(b.tip / 2, rb2); // (a ring's tip under its base circle doesn't roll)
476
+ awAt = Math.acos(Math.min(1, (rb2 - rb1) / at));
477
+ path = Math.sqrt(ra1 ** 2 - rb1 ** 2) - Math.sqrt(ra2 ** 2 - rb2 ** 2) + at * Math.sin(awAt);
478
+ } else {
479
+ path = Math.sqrt(ra1 ** 2 - rb1 ** 2) - r1 * Math.sin(al) + (m * b.rack.addendum - (at - r1)) / Math.sin(al);
480
+ }
481
+ let contact = path / pb;
470
482
  // the overlap ratio: how far a tooth's own twist carries the contact on across the width (εβ = b tan β / π m, each
471
483
  // half of a herringbone on its own)
472
484
  const overlap = ha > 0 && width !== undefined ? ((a.herringbone ? width / 2 : width) * Math.tan(ha * DEG)) / (Math.PI * m) : 0;
473
485
  if (overlap) contact += overlap;
474
486
  const sense = b.kind === 'rack' ? `${fmt(ratio)} mm of rack a turn (${fmt(ratio / 360, 4)} mm a degree)` : `${fmt(Math.abs(ratio), 4)} turns of the second for each turn of the first (${a.teeth}:${b.teeth}), ${ratio < 0 ? 'turning opposite ways' : 'the same way'}`;
475
- if (contact < 1) f('fail', `contact ratio ${fmt(contact)}: under 1, a pair of teeth lets go before the next takes up, and the drive jumps: more teeth, or a longer addendum`, 'mesh.contact', { contact });
476
- else if (contact < 1.2) f('warn', `contact ratio ${fmt(contact)}: under 1.2 the drive is rough, and a printed tooth's errors can make it jump`, 'mesh.contact', { contact });
477
- else f('pass', `contact ratio ${fmt(contact)}${overlap ? ` (${fmt(contact - overlap)} across the teeth and ${fmt(overlap)} along their twist)` : ''}: ${fmt(contact)} pairs of teeth share the load on average`, 'mesh.contact', { contact });
487
+ const where = given ? ` at the ${fmt(at, 3)} mm centre given (${fmt(need, 3)} mm is where they mesh as drawn)` : '';
488
+ // (judged on the path across the teeth: a helical's twist carries on a contact that is there, it makes none)
489
+ if (crowded) f('fail', `the axes are too close${where || ` at ${fmt(at, 3)} mm`}: ${at > 0 ? 'the gears\' base circles overlap, so the teeth can\'t roll on each other' : 'the distance between them has to be above 0'}, and they jam: bring the axes to ${fmt(need, 3)} mm`, 'mesh.contact', { contact, centre: at });
490
+ else if (!(path > 0)) f('fail', `the teeth don't reach each other${where || ` at ${fmt(at, 3)} mm`}: no pair ever takes up the drive, and the gears slip round: bring the axes to ${fmt(need, 3)} mm`, 'mesh.contact', { contact, centre: at });
491
+ else if (contact < 1) f('fail', `contact ratio ${fmt(contact)}${where}: under 1, a pair of teeth lets go before the next takes up, and the drive jumps: ${given && centre > need ? `bring the axes closer, to ${fmt(need, 3)} mm, or ` : ''}more teeth, or a longer addendum`, 'mesh.contact', { contact, centre: at });
492
+ else if (contact < 1.2) f('warn', `contact ratio ${fmt(contact)}${where}: under 1.2 the drive is rough, and a printed tooth's errors can make it jump`, 'mesh.contact', { contact, centre: at });
493
+ else f('pass', `contact ratio ${fmt(contact)}${overlap ? ` (${fmt(contact - overlap)} across the teeth and ${fmt(overlap)} along their twist)` : ''}${where}: ${fmt(contact)} pairs of teeth share the load on average`, 'mesh.contact', { contact, centre: at });
494
+ // The room under each tip, where the axes are: the centre distance less one gear's tip and the other's root (for a
495
+ // ring, its root less the pinion's far tip, and its own tips outside the pinion's roots). Profile shift pushes the
496
+ // tips out and the gears apart by less than it pushes the tips, so a shifted pair loses the 0.25 module it was drawn
497
+ // with: ISO 21771 and KHK shorten each tip by (x1 + x2 − y) modules, y being how far the shift moved the centre.
498
+ // The tips are drawn full, as each gear is drawn without its mate, so this says how much to take off.
499
+ const clear = b.kind === 'external' ? [at - ra1 - b.root / 2, at - b.tip / 2 - rf1]
500
+ : b.kind === 'internal' ? [b.root / 2 - at - ra1, b.tip / 2 - at - rf1]
501
+ : [at - ra1 - b.rootLine, at - rf1 - b.tipLine];
502
+ const least = Math.min(...clear), drawn = m * (a.rack.dedendum - a.rack.addendum), names = ['the first gear\'s tips', `the ${b.kind === 'internal' ? 'ring' : b.kind === 'rack' ? 'rack' : 'second gear'}'s tips`];
503
+ // The shortening is reckoned where the gears belong: axes set tighter than that (outer gears or a rack closer, a
504
+ // pinion further out in its ring) want moving back, not shorter tips; at a looser centre, the room there
505
+ const tighter = (b.kind === 'internal' ? at - need : need - at) > 0.005, room = tighter ? clear.map((x) => x + Math.abs(need - at)) : clear;
506
+ const addenda = [a.rack.addendum, b.rack.addendum], short = room.map((x) => Math.max(0, drawn - x) / m), cut = short.map((k, i) => +(addenda[i] - k).toFixed(3));
507
+ const shorten = short.some((k) => k > 1e-3) ? `shorten ${short.every((k) => k > 1e-3) ? 'both gears\' tips' : names[short[0] > 1e-3 ? 0 : 1]} to give back the ${fmt(drawn, 3)} mm of room they were drawn with (${short.map((k, i) => (k > 1e-3 ? `addendum: ${cut[i]} on ${i ? 'the second' : 'the first'}` : '')).filter(Boolean).join(', ')}), or less profile shift` : '';
508
+ const advice = tighter ? `${b.kind === 'internal' ? `bring the pinion's axis to ${fmt(need, 3)} mm from the ring's` : b.kind === 'rack' ? `lift the pinion's axis to ${fmt(need, 3)} mm from the rack's pitch line` : `move the axes apart, to ${fmt(need, 3)} mm`}${shorten ? `, and ${shorten}` : ''}` : shorten || 'less profile shift';
509
+ const worst = names[clear[0] <= clear[1] ? 0 : 1];
510
+ if (least < 0) f('fail', `${worst} reach ${fmt(-least, 3)} mm into the mate's roots${where || ` at ${fmt(at, 3)} mm`}: the teeth jam: ${advice}`, 'mesh.tipClearance', { clearance: least, centre: at, addendum: cut });
511
+ else if (least < 0.1 * m) f('warn', `${fmt(least, 3)} mm of room under ${worst}${where} (drawn with ${fmt(drawn, 3)}): a print that comes out a little fat rubs there: ${advice}`, 'mesh.tipClearance', { clearance: least, centre: at, addendum: cut });
512
+ else f('pass', `${fmt(least, 3)} mm of room under the tips${where}`, 'mesh.tipClearance', { clearance: least, centre: at, addendum: cut });
513
+ if (b.kind === 'internal') {
514
+ // A pinion in a ring: as a pinion tooth leaves the ring's space its tip swings out past the ring tooth's corner
515
+ // (trochoid interference). KHK's condition (Gear Technical Reference, internal gears), which honours shift and the
516
+ // centre: θ1 z1/z2 + inv αw − inv αa2 ≥ θ2, with θ1 = acos((ra2² − ra1² − a²) / 2a ra1) + inv αa1 − inv αw and
517
+ // θ2 = acos((a² + ra2² − ra1²) / 2a ra2), in radians of the ring's turn. It replaces the rule of thumb that a ring
518
+ // needs 10 teeth more than its pinion, which failed rings that clear (20 in 28) and passed shifted ones that don't.
519
+ // KHK's other condition, involute interference, assumes a cutter's root under the pinion's base circle; the kit's
520
+ // flanks run straight in there, and contact() tests the outlines as drawn.
521
+ const ra2 = b.tip / 2, rb2 = b.base / 2, z = a.teeth / b.teeth;
522
+ const k1 = (ra2 ** 2 - ra1 ** 2 - at ** 2) / (2 * at * ra1), k2 = (at ** 2 + ra2 ** 2 - ra1 ** 2) / (2 * at * ra2);
523
+ if (Math.abs(k1) <= 1 && Math.abs(k2) <= 1) {
524
+ const aa1 = Math.acos(rb1 / ra1), aa2 = Math.acos(rb2 / Math.max(ra2, rb2));
525
+ const t1 = Math.acos(k1) + inv(aa1) - inv(awAt), t2 = Math.acos(k2);
526
+ const margin = t1 * z + inv(awAt) - inv(aa2) - t2;
527
+ // each tooth's share of the backlash on one flank (a quarter of each gear's), as the same angle of the ring
528
+ const play = (a.backlash / 4 / r1) * z + b.backlash / 4 / (b.pitch / 2), mm = (x) => fmt(x * (b.pitch / 2), 3);
529
+ const gap = b.teeth - a.teeth, values = { gap, margin: margin * (b.pitch / 2), play: play * (b.pitch / 2) };
530
+ if (margin + play < 0) f('fail', `the pinion's tips foul the ring's as they leave (${mm(-(margin + play))} mm of overlap at the ring's pitch circle, with the backlash${where}): a ring of ${gap} teeth more than its pinion is too close for these teeth: more teeth on the ring, fewer on the pinion, or shift the ring out (a positive shift)`, 'mesh.interference', values);
531
+ else if (margin < 0) f('warn', `the pinion's tips clear the ring's as they leave by the backlash alone (${mm(margin + play)} mm at the ring's pitch circle${where}): teeth that print a little fat foul; check the pair with contact()`, 'mesh.interference', values);
532
+ else f('pass', `the pinion's tips clear the ring's as they leave, by ${mm(margin)} mm at the ring's pitch circle with no backlash`, 'mesh.interference', values);
533
+ }
534
+ }
478
535
  let backlash = a.backlash / 2 + b.backlash / 2;
479
536
  if (centre !== undefined) {
480
- if (!isNum(centre)) throw new Error(`mesh: centre is a distance in mm (got ${shown(centre)})`);
481
- const off = centre - need;
482
- // further apart opens a gap along the line of action of 2 Δa sin αw, which is 2 Δa tan αw round the pitch circle
537
+ // how much looser than they need: further apart for outer gears and a rack; for a pinion in a ring, nearer the
538
+ // ring's centre, as moving it out pushes its teeth into the ring's
539
+ const ring = b.kind === 'internal', off = (ring ? -1 : 1) * (centre - need), by = fmt(Math.abs(centre - need), 3);
540
+ const tight = ring ? `the pinion's axis is ${by} mm further from the ring's than these gears need (${fmt(need, 3)} mm)` : `the axes are ${by} mm closer than these gears need (${fmt(need, 3)} mm${b.kind === 'rack' ? ', centre to the rack\'s pitch line' : ''})`;
541
+ const loose = ring ? `the pinion's axis is ${by} mm nearer the ring's than these gears need (${fmt(need, 3)} mm)` : `the axes are ${by} mm further apart than these gears need (${fmt(need, 3)} mm)`;
542
+ // looser opens a gap along the line of action of 2 Δa sin αw, which is 2 Δa tan αw round the pitch circle
483
543
  const added = 2 * off * Math.tan(aw);
484
544
  backlash += added;
485
- // closer than they need eats the backlash (2 Δa tan αw of it) and the clearance under the tips (0.25 m); past
486
- // either, the teeth jam
545
+ // tighter eats the backlash (2 Δa tan αw of it) and the clearance under the tips (0.25 m); past either, the teeth jam
487
546
  const tipRoom = m * (Math.min(a.rack.dedendum, b.rack?.dedendum ?? a.rack.dedendum) - Math.max(a.rack.addendum, b.rack?.addendum ?? a.rack.addendum)) + off;
488
- if (backlash < 0 || tipRoom < 0) f('fail', `the axes are ${fmt(-off, 3)} mm closer than these gears need (${fmt(need, 3)} mm${b.kind === 'rack' ? ', centre to the rack\'s pitch line' : ''}): ${backlash < 0 ? `more than their ${fmt(a.backlash / 2 + b.backlash / 2, 2)} mm of backlash allows` : 'the tips reach the roots'}, and the teeth jam`, 'mesh.centre', { centre, need });
489
- else if (off < -0.005 && backlash < 0.05) f('warn', `the axes are ${fmt(-off, 3)} mm closer than these gears need (${fmt(need, 3)} mm): ${fmt(backlash, 3)} mm of play left, tight enough to bind as printed`, 'mesh.centre', { centre, need });
490
- else if (backlash > 0.4) f('warn', `the axes are ${fmt(off, 3)} mm further apart than these gears need (${fmt(need, 3)} mm): ${fmt(backlash, 2)} mm of backlash, loose enough to knock`, 'mesh.centre', { centre, need });
491
- else f('pass', `centre distance ${fmt(centre, 3)} mm, ${Math.abs(off) > 0.005 ? `${fmt(Math.abs(off), 3)} mm ${off > 0 ? 'further apart' : 'closer'} than the ${fmt(need, 3)} they need` : 'as they need'}: ${fmt(backlash, 2)} mm of backlash`, 'mesh.centre', { centre, need });
547
+ if (backlash < 0 || tipRoom < 0) f('fail', `${tight}: ${backlash < 0 ? `more than their ${fmt(a.backlash / 2 + b.backlash / 2, 2)} mm of backlash allows` : 'the tips reach the roots'}, and the teeth jam`, 'mesh.centre', { centre, need });
548
+ else if (off < -0.005 && backlash < 0.05) f('warn', `${tight}: ${fmt(backlash, 3)} mm of play left, tight enough to bind as printed`, 'mesh.centre', { centre, need });
549
+ else if (backlash > 0.4) f('warn', `${loose}: ${fmt(backlash, 2)} mm of backlash, loose enough to knock`, 'mesh.centre', { centre, need });
550
+ else f('pass', `centre distance ${fmt(centre, 3)} mm, ${Math.abs(centre - need) > 0.005 ? `${by} mm ${centre > need ? 'further apart' : 'closer'} than the ${fmt(need, 3)} they need` : 'as they need'}: ${fmt(backlash, 2)} mm of backlash`, 'mesh.centre', { centre, need });
492
551
  }
493
552
  const thrust = a.herringbone || !ha ? 0 : Math.tan(ha * DEG);
494
- return { kind: b.kind, centre: need, ratio, contact, overlap, thrust, pressureAngle: aw / DEG, backlash, text: sense, findings: out };
553
+ return { kind: b.kind, centre: need, ratio, contact, overlap, thrust, pressureAngle: awAt / DEG, clearance: least, backlash, text: sense, findings: out };
495
554
  }
496
555
  const flip = (r) => ({ ...r, ratio: r.kind === 'rack' ? r.ratio : 1 / r.ratio });
497
556
  const fmt = (x, d = 2) => String(+x.toFixed(d));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/gears",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Gears for printed parts: involute spur gears, racks and ring gears drawn from their rules, with their numbers, how a pair meshes (centre distance, ratio, contact ratio, phase) and how they print.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,23 +14,12 @@
14
14
  }
15
15
  },
16
16
  "files": [
17
- "gears.mjs",
18
- "core.mjs",
19
- "planetary.mjs",
20
- "contact.mjs",
21
- "tooth.mjs",
22
- "worm.mjs",
23
- "diagram.mjs",
24
- "gears.d.mts",
25
- "core.d.mts",
26
- "planetary.d.mts",
27
- "contact.d.mts",
28
- "tooth.d.mts",
29
- "worm.d.mts",
30
- "diagram.d.mts",
17
+ "*.mjs",
18
+ "*.d.mts",
31
19
  "README.md",
32
20
  "CHANGELOG.md",
33
- "LICENSE"
21
+ "LICENSE",
22
+ "!test.mjs"
34
23
  ],
35
24
  "license": "MIT",
36
25
  "keywords": [
@@ -62,6 +51,6 @@
62
51
  },
63
52
  "types": "./gears.d.mts",
64
53
  "dependencies": {
65
- "@rulecad/fea": "^0.2.9"
54
+ "@rulecad/fea": "^0.3.0"
66
55
  }
67
56
  }