@rulecad/gears 0.1.1 → 0.3.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/README.md +100 -2
- package/contact.d.mts +31 -0
- package/contact.mjs +79 -0
- package/gears.d.mts +162 -1
- package/gears.mjs +201 -17
- package/package.json +13 -2
- package/planetary.d.mts +36 -0
- package/planetary.mjs +77 -0
- package/tooth.d.mts +25 -0
- package/tooth.mjs +72 -0
- package/worm.d.mts +72 -0
- package/worm.mjs +92 -0
package/README.md
CHANGED
|
@@ -47,6 +47,8 @@ its numbers come from.
|
|
|
47
47
|
| Spur gear | Teeth on the outside, straight across. Prints flat on the bed with no supports, its teeth in the layers. | `spur({ module, teeth, width, bore?, flat? })` |
|
|
48
48
|
| Rack | A gear of infinite radius: straight teeth on a bar, for a slide driven by a pinion. | `rack({ module, teeth, width, height? })` |
|
|
49
49
|
| Ring gear | Teeth on the inside of a ring, for a pinion turning within it (planetary gearboxes). Turns the same way as its pinion. | `internal({ module, teeth, width, rim? })` |
|
|
50
|
+
| Helical gear | A spur gear's teeth turned along the width by the helix angle: smoother and quieter, more teeth in mesh, but it pushes along its axis. | `helical({ module, teeth, width, helix, hand? })` |
|
|
51
|
+
| Herringbone | Helical one way to the middle and back: no push along the axis, it stays on its shaft and centres itself. Prints with no supports. | `herringbone({ module, teeth, width, helix? })` (30° by default) |
|
|
50
52
|
|
|
51
53
|
Each has a model with its numbers (`gearModel`, `rackModel`, `internalModel`) and an outline in 2D (`spurProfile`,
|
|
52
54
|
`rackProfile`, `internalProfile`: loops of `[x, y]` points). A spur gear's first tooth is on +x, its axis along z. A
|
|
@@ -64,6 +66,7 @@ What every gear takes:
|
|
|
64
66
|
| `width` | (required for a solid) | Up z. A whole number of layers prints as drawn. |
|
|
65
67
|
| `chamfer` | 0.3 mm, at most a quarter module | Round the bed face, so the first layer's squish doesn't widen the teeth there. `[bed, top]` for both faces. |
|
|
66
68
|
| `bore`, `flat` | none | A hole for a shaft, and the depth of a flat across it (a D shaft). |
|
|
69
|
+
| `helix`, `hand`, `herringbone` | 0°, right, no | Helical teeth: the angle (up to 45°), which way they turn (`"right"` turns anticlockwise up z), and whether they turn back at the middle. Racks and rings take them too. `module` and `pressureAngle` stay the transverse ones, so the centre distance is a spur gear's. |
|
|
67
70
|
|
|
68
71
|
## How a pair meshes
|
|
69
72
|
|
|
@@ -75,12 +78,64 @@ What every gear takes:
|
|
|
75
78
|
- **`contact`**: the contact ratio, how many pairs of teeth share the load on average. Under 1 the drive jumps; under
|
|
76
79
|
1.2 it is rough.
|
|
77
80
|
- **`backlash`**: the play, with the centre you gave.
|
|
78
|
-
- **`
|
|
79
|
-
|
|
81
|
+
- **`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).
|
|
80
86
|
|
|
81
87
|
`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`,
|
|
82
88
|
with `angle` the direction from a's centre to b's. `rackPhase(pinion, at)` does the same for a rack.
|
|
83
89
|
|
|
90
|
+
## Planetary gearboxes
|
|
91
|
+
|
|
92
|
+
A sun in the middle, planets round it on a carrier, and a ring round them all. Hold one of the three and the other two
|
|
93
|
+
turn at a ratio set by the teeth alone. `planetary({ module, ratio, planets, held, input, output, size })` finds the
|
|
94
|
+
teeth for a ratio that also put together, nearest the ratio first and then the smallest:
|
|
95
|
+
|
|
96
|
+
- the ring is the sun and two planets across: R = S + 2P;
|
|
97
|
+
- the planets go in evenly spaced: S + R a whole number of times the number of planets;
|
|
98
|
+
- the planets' tips clear each other by a module, and the ring has at least 12 teeth more than a planet;
|
|
99
|
+
- the sun and planets have 17 teeth or more (`least`), so none is undercut; the rim fits `size` if given.
|
|
100
|
+
|
|
101
|
+
`best` holds the teeth (ring held, sun in, carrier out, 5:1: a sun of 18, three planets of 27, a ring of 72), each
|
|
102
|
+
planet's place round the carrier and the turn that puts it in phase with the sun, and the ring's turn. When no set
|
|
103
|
+
gives the ratio exactly, the nearest is returned and `planetary.ratio` says how far off it is (a fail past 5%).
|
|
104
|
+
`planetaryRatio({ sun, ring }, { held, input, output })` is the ratio of any teeth, any way round.
|
|
105
|
+
|
|
106
|
+
## Worms and bevel gears
|
|
107
|
+
|
|
108
|
+
A **worm** is a screw whose thread, cut along its axis, is the basic rack's tooth: `worm({ module, starts, diameter,
|
|
109
|
+
length, bore })` draws it along z. Its wheel is a helical gear at the worm's lead angle and of its hand,
|
|
110
|
+
`wormWheel(wormSpec, { teeth, width, bore })` (the usual printable wheel: not throated, so they touch at a point,
|
|
111
|
+
which printed teeth spread). `wormMesh(wormSpec, { teeth })` gives the centre distance, the ratio (`starts` teeth of the
|
|
112
|
+
wheel for each turn of the worm), whether it **locks** (the lead angle under the friction angle: the wheel can't turn
|
|
113
|
+
the worm back; `worm.locks`) and how **efficient** it is. A single start of module 1 on a 10 mm worm: a 5.71° lead,
|
|
114
|
+
it locks at μ 0.25, 27% efficient. Three starts on 8 mm: 20.6°, it doesn't.
|
|
115
|
+
|
|
116
|
+
A **bevel gear** carries a turn round a corner. `bevel({ module, teeth, mate, shaftAngle, width, bore })` draws a
|
|
117
|
+
straight bevel by Tredgold's construction: the tooth drawn on the back cone as a spur gear of z / cos δ teeth, wrapped
|
|
118
|
+
onto the back cone and seen from the apex onto the back end, every section nearer the apex that one scaled, so the
|
|
119
|
+
teeth run straight to the apex. The back end is on the bed and the apex up z. `bevelModel` gives the pitch cone angle
|
|
120
|
+
(tan δ = sin Σ / (z₂/z₁ + cos Σ)), the cone distance R, the virtual teeth, and refuses a face width over R / 3;
|
|
121
|
+
`bevelMesh` the ratio and the contact ratio of the back cones' equivalent spur gears. In an assembly, the two cones
|
|
122
|
+
must share their apex.
|
|
123
|
+
|
|
124
|
+
## The mesh, measured
|
|
125
|
+
|
|
126
|
+
`mesh()` reckons a pair from the formulas. `contact(a, b, { centre, steps })` measures it from the teeth as drawn,
|
|
127
|
+
with their fillets, rounds and backlash and the centre distance given. It turns the driver through one tooth in steps,
|
|
128
|
+
and at each step turns the driven gear each way until its outline meets the driver's:
|
|
129
|
+
|
|
130
|
+
- **backlash**: the turn between the two meetings, as play at the pitch circle (`mesh.backlash`, a warn when it falls
|
|
131
|
+
under 0.02 mm);
|
|
132
|
+
- **transmission error**: how far the driven gear's forward meeting wanders across a tooth (`mesh.error`);
|
|
133
|
+
- **interference**: steps where the outlines already cross where the ratio puts them (`mesh.interference`).
|
|
134
|
+
|
|
135
|
+
`a` and `b` are the parameters the models take; `b.kind` is `'internal'` for a ring or `'rack'` for a rack. For 18
|
|
136
|
+
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
|
|
137
|
+
error; with the axes 0.2 mm apart, 0.30 mm (2 Δa tan α more). `cad check` measures every mesh in an assembly this way.
|
|
138
|
+
|
|
84
139
|
## How it prints
|
|
85
140
|
|
|
86
141
|
`printable(model, printer, width)` reads the gear against the printer (`{ line, layer, nozzle, wall_min }`, as in
|
|
@@ -90,6 +145,7 @@ with `angle` the direction from a's centre to b's. `rackPhase(pinion, at)` does
|
|
|
90
145
|
- `gear.root`: a tooth narrower at its root than the thinnest wall.
|
|
91
146
|
- `gear.tip`: tips narrower than a line print as one bead.
|
|
92
147
|
- `gear.layers`: a width that isn't a whole number of layers.
|
|
148
|
+
- `gear.helix`: helical teeth lean most at their tips; past 45° the flanks sag. `gear.thrust` says the push along the axis.
|
|
93
149
|
|
|
94
150
|
Spur gears, racks and rings all print flat, with no supports: the teeth are in the layers, where the filament is
|
|
95
151
|
strongest. Every tooth has a round at its root (the commonest place a tooth cracks) and at its tip.
|
|
@@ -97,6 +153,31 @@ strongest. Every tooth has a round at its root (the commonest place a tooth crac
|
|
|
97
153
|
The defaults, each with its rule, are in `DEFAULTS`. The backlash, the chamfer, the tip round and the smallest module
|
|
98
154
|
are estimates until a printed sampler measures them.
|
|
99
155
|
|
|
156
|
+
## How strong it is
|
|
157
|
+
|
|
158
|
+
`strength(model, { width, material, torque?, safety?, speed? })` reads the teeth by the Lewis equation: the bending
|
|
159
|
+
stress at a tooth's root with the whole load at its tip, σ = F_t / (b m Y), Y the Lewis form factor for its teeth
|
|
160
|
+
(`lewisFactor(z)`). Given a torque (N·mm), it says the stress and how far under the material's strength
|
|
161
|
+
(`gear.strength`: a warn under the safety factor, 2 by default; a fail past the strength). Without one, it says the
|
|
162
|
+
torque the gear carries at the safety factor. Helical teeth are read in their normal section; a speed (rpm) adds
|
|
163
|
+
Barth's velocity factor.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
strength(gearModel({ module: 1, teeth: 18 }), { width: 6, material: { strength: 39, name: 'PLA' }, torque: 500 });
|
|
167
|
+
// at 0.5 N·m the teeth see 30 MPa at their roots (Lewis, Y 0.309): 1.3× under PLA's 39 MPa, under the 2× asked
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
It is a first number. A printed tooth is weaker than a moulded one where its layers and voids are, and stronger than
|
|
171
|
+
Lewis says where the root fillet and its neighbours share the load. Where it matters, print one and load it.
|
|
172
|
+
|
|
173
|
+
Where it matters, `toothStress(params, { width, torque, material: { E, nu, strength } })` analyses one tooth by
|
|
174
|
+
finite elements (`@rulecad/fea`, plane stress): the tooth and a slice of rim, the rim's cut edges held, the load at
|
|
175
|
+
the tip along the line of action. It gives the peak stress at the root of the loaded side, with the fillet as drawn,
|
|
176
|
+
and runs a grid a third coarser to say whether it has settled (`gear.fe.coarse` when it moved over 5%). For 18 teeth
|
|
177
|
+
it reads about 1.33× Lewis, and 1.25× for 40: the fillet's stress concentration, which Lewis leaves out (AGMA's
|
|
178
|
+
geometry factor for a tip-loaded 18-tooth pinion implies about 1.3).
|
|
179
|
+
|
|
180
|
+
|
|
100
181
|
## What isn't refused, and what is
|
|
101
182
|
|
|
102
183
|
A model or a solid refuses what isn't a gear, by name, before any maths: `gearModel: teeth is a whole number of 6 or
|
|
@@ -118,7 +199,20 @@ a point.
|
|
|
118
199
|
| Contact ratio | (√(r_a1² − r_b1²) + √(r_a2² − r_b2²) − a sin α_w) / (π m cos α) | Dudley (1984); KHK |
|
|
119
200
|
| Rack contact | (√(r_a² − r_b²) − r sin α + m (h_a − x) / sin α) / (π m cos α) | KHK |
|
|
120
201
|
| Root fillet | 0.38 m | ISO 53 profile A |
|
|
202
|
+
| Helical twist | the profile turns z tan β / r up the width | ISO 21771 (transverse module) |
|
|
203
|
+
| Overlap ratio | ε_β = b tan β / π m (each half of a herringbone on its own) | ISO 21771 |
|
|
204
|
+
| Thrust | F_a = F_t tan β | Dudley (1984) |
|
|
205
|
+
| Flank lean at the tip | tan β_a = tan β · r_a / r | ISO 21771 |
|
|
121
206
|
| Ring and pinion | at least 10 teeth apart (12 to be safe) at 20° | KHK, internal gears |
|
|
207
|
+
| Planetary ratio | (ω_s − ω_c) / (ω_r − ω_c) = −R / S; ring held, sun in: 1 + R / S | Willis; Dudley (1984), ch. 3 |
|
|
208
|
+
| Planetary assembly | R = S + 2P; (S + R) / n whole; 2a sin(π / n) > d_a,planet | KHK, planetary gears |
|
|
209
|
+
| Tooth bending (Lewis) | σ = K_v F_t / (b m Y); helical: m cos β, z / cos³β teeth | Budynas and Nisbett, Shigley's Mechanical Engineering Design, 10th ed., §14-1 and Table 14-2 |
|
|
210
|
+
| Velocity factor (Barth, cut profile) | K_v = (3.05 + V) / 3.05, V in m/s | Shigley, eq. 14-4b |
|
|
211
|
+
| Tooth by finite elements | plane stress, 32 cells a module, load F_t / cos α along the line of action at the tip | `@rulecad/fea`; AGMA 908-B89 for the geometry factor it is compared with |
|
|
212
|
+
| Worm lead angle | tan γ = s π m / (π d) | ISO 21771 (worms: ISO/TR 10828) |
|
|
213
|
+
| Worm locking and efficiency | locks when γ < atan μ; η = tan γ (cos α_n − μ tan γ) / (cos α_n tan γ + μ) | Dudley (1984), ch. 3; Shigley, §13-11 |
|
|
214
|
+
| Bevel pitch cone | tan δ₁ = sin Σ / (z₂/z₁ + cos Σ); R = r / sin δ; virtual teeth z / cos δ | Tredgold's approximation; Shigley, §13-12 |
|
|
215
|
+
| Bevel face width | at most R / 3 | AGMA 2005 |
|
|
122
216
|
|
|
123
217
|
## Words used
|
|
124
218
|
|
|
@@ -133,7 +227,10 @@ a point.
|
|
|
133
227
|
| Contact ratio | The path of contact over the base pitch: how many pairs of teeth share the load on average. |
|
|
134
228
|
| Profile shift | Moving the teeth outwards (or in) by a fraction of the module, without changing the module or the teeth. |
|
|
135
229
|
| Backlash | Play between mating teeth, so they don't bind as printed parts vary. |
|
|
230
|
+
| Helix angle | How far helical teeth lean from straight across, at the pitch circle. |
|
|
231
|
+
| Hand | Which way helical teeth turn. Two outer gears that mesh are of opposite hands. |
|
|
136
232
|
| Undercut | A pinion of few teeth having its flank cut away under the base circle, or its mate's tip fouling there. |
|
|
233
|
+
| Sun, planets, carrier, ring | A planetary gearbox's parts: the middle gear, the gears round it, what holds the planets' axles, and the ring gear round them all. |
|
|
137
234
|
|
|
138
235
|
## Sources
|
|
139
236
|
|
|
@@ -141,3 +238,4 @@ a point.
|
|
|
141
238
|
- ISO 21771:2007, *Gears: cylindrical involute gears and gear pairs, concepts and geometry*.
|
|
142
239
|
- D. W. Dudley, *Handbook of Practical Gear Design*, McGraw-Hill, 1984.
|
|
143
240
|
- KHK, *Gear Technical Reference* (khkgears.net): undercut, profile shift, internal gears.
|
|
241
|
+
- R. G. Budynas and J. K. Nisbett, *Shigley's Mechanical Engineering Design*, 10th ed., McGraw-Hill, 2015: the Lewis equation and form factors.
|
package/contact.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mesh of a pair as drawn: backlash, transmission error and interference across one pitch of the driver.
|
|
3
|
+
* a: the driver's parameters (as gearModel takes them); b: the driven's (kind 'internal' for a ring, 'rack' for a rack).
|
|
4
|
+
* @param {object} a @param {object & { kind?: 'external' | 'internal' | 'rack' }} b
|
|
5
|
+
* @param {{ centre?: number, steps?: number }} [o] centre: the axes' distance (default: what they need)
|
|
6
|
+
*/
|
|
7
|
+
export function contact(a: object, b: object & {
|
|
8
|
+
kind?: "external" | "internal" | "rack";
|
|
9
|
+
}, { centre, steps }?: {
|
|
10
|
+
centre?: number;
|
|
11
|
+
steps?: number;
|
|
12
|
+
}): {
|
|
13
|
+
rows: ({
|
|
14
|
+
angle: number;
|
|
15
|
+
interferes: boolean;
|
|
16
|
+
backlash?: undefined;
|
|
17
|
+
error?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
angle: number;
|
|
20
|
+
backlash: any;
|
|
21
|
+
error: any;
|
|
22
|
+
interferes?: undefined;
|
|
23
|
+
})[];
|
|
24
|
+
backlash: {
|
|
25
|
+
least: number;
|
|
26
|
+
most: number;
|
|
27
|
+
};
|
|
28
|
+
error: number;
|
|
29
|
+
reckoned: any;
|
|
30
|
+
findings: any[];
|
|
31
|
+
};
|
package/contact.mjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// The mesh measured, not reckoned: the drawn teeth turned through a pitch, and at each step the driven gear turned
|
|
2
|
+
// each way until its outline meets the driver's. The turn between the two meetings is the backlash as drawn (with the
|
|
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.
|
|
6
|
+
import { spurProfile, internalProfile, rackProfile, gearModel, internalModel, rackModel, mesh, phase, rackPhase } from './gears.mjs';
|
|
7
|
+
|
|
8
|
+
const DEG = Math.PI / 180;
|
|
9
|
+
const fmt = (x, d = 3) => String(+x.toFixed(d));
|
|
10
|
+
|
|
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;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
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; };
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The mesh of a pair as drawn: backlash, transmission error and interference across one pitch of the driver.
|
|
30
|
+
* a: the driver's parameters (as gearModel takes them); b: the driven's (kind 'internal' for a ring, 'rack' for a rack).
|
|
31
|
+
* @param {object} a @param {object & { kind?: 'external' | 'internal' | 'rack' }} b
|
|
32
|
+
* @param {{ centre?: number, steps?: number }} [o] centre: the axes' distance (default: what they need)
|
|
33
|
+
*/
|
|
34
|
+
export function contact(a, b, { centre, steps = 24 } = {}) {
|
|
35
|
+
const kind = b.kind ?? 'external';
|
|
36
|
+
const ga = gearModel(a), gb = kind === 'internal' ? internalModel(b) : kind === 'rack' ? rackModel(b) : gearModel(b);
|
|
37
|
+
const m = mesh(ga, gb, centre === undefined ? {} : { centre }), c = centre ?? m.centre, mod = ga.module;
|
|
38
|
+
const A = spurProfile(a).loops[0];
|
|
39
|
+
const B = kind === 'internal' ? internalProfile(b).loops[1] : kind === 'rack' ? rackProfile(b).loops[0] : spurProfile(b).loops[0];
|
|
40
|
+
// where the driven sits, and how it moves: an angle (degrees) about its centre, or along the rack (mm)
|
|
41
|
+
const per = kind === 'rack' ? (Math.PI * ga.pitch) / 360 : m.ratio, r2 = kind === 'rack' ? null : gb.pitch / 2;
|
|
42
|
+
const base = kind === 'rack' ? rackPhase(ga, 0) : phase(ga, gb, kind === 'internal' ? 180 : 0);
|
|
43
|
+
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;
|
|
45
|
+
const drivenAt = (deg, nudge) => kind === 'rack'
|
|
46
|
+
? 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
|
+
: turn(B, (m.ratio * deg + base + nudge) * DEG, O2);
|
|
48
|
+
const driverAt = (deg) => turn(A, deg * DEG, kind === 'rack' ? [0, c] : [0, 0]);
|
|
49
|
+
// the turn (degrees, or mm for a rack) each way from the ratio's place to where the outlines first meet
|
|
50
|
+
const span = kind === 'rack' ? Math.PI * mod / 2 : 180 / gb.teeth;
|
|
51
|
+
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;
|
|
54
|
+
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; }
|
|
56
|
+
return lo;
|
|
57
|
+
};
|
|
58
|
+
const rows = [];
|
|
59
|
+
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));
|
|
62
|
+
if (clash) { rows.push({ angle: deg, interferes: true }); continue; }
|
|
63
|
+
// the driven pushed on (it lags until its flank meets the driver's: the driver turning +, the driven its way)
|
|
64
|
+
const ahead = meet(deg, Math.sign(per)), behind = meet(deg, -Math.sign(per));
|
|
65
|
+
const toMm = (x) => (kind === 'rack' ? x : x * DEG * r2);
|
|
66
|
+
rows.push({ angle: deg, backlash: toMm(ahead + behind), error: toMm(behind) });
|
|
67
|
+
}
|
|
68
|
+
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;
|
|
72
|
+
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) });
|
|
73
|
+
if (ok.length) {
|
|
74
|
+
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
|
+
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
|
+
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
|
+
}
|
|
78
|
+
return { rows, backlash: { least, most }, error: swing, reckoned: m.backlash, findings: out };
|
|
79
|
+
}
|
package/gears.d.mts
CHANGED
|
@@ -33,6 +33,10 @@ export function rackModel(p: GearSpec & {
|
|
|
33
33
|
backlash: any;
|
|
34
34
|
height: any;
|
|
35
35
|
thickness: number;
|
|
36
|
+
helix: any;
|
|
37
|
+
hand: any;
|
|
38
|
+
herringbone: boolean;
|
|
39
|
+
thrust: number;
|
|
36
40
|
length: number;
|
|
37
41
|
tipLine: number;
|
|
38
42
|
rootLine: number;
|
|
@@ -87,6 +91,10 @@ export function rackProfile(p: any, grow?: number): {
|
|
|
87
91
|
backlash: any;
|
|
88
92
|
height: any;
|
|
89
93
|
thickness: number;
|
|
94
|
+
helix: any;
|
|
95
|
+
hand: any;
|
|
96
|
+
herringbone: boolean;
|
|
97
|
+
thrust: number;
|
|
90
98
|
length: number;
|
|
91
99
|
tipLine: number;
|
|
92
100
|
rootLine: number;
|
|
@@ -110,6 +118,15 @@ export function rackProfile(p: any, grow?: number): {
|
|
|
110
118
|
* @returns {object} a JSCAD geom3
|
|
111
119
|
*/
|
|
112
120
|
export function spur(p: GearSpec & Solid): object;
|
|
121
|
+
/** A helical gear: a spur gear's profile turned along its width by the helix angle. Meshes with one of the opposite hand. @param {GearSpec & Solid & { helix: number, hand?: 'right' | 'left' }} p */
|
|
122
|
+
export function helical(p: GearSpec & Solid & {
|
|
123
|
+
helix: number;
|
|
124
|
+
hand?: "right" | "left";
|
|
125
|
+
}): any;
|
|
126
|
+
/** A herringbone gear: helical one way to the middle of its width and back, so it pushes no thrust along its axis and stays on its shaft. Prints with no supports. @param {GearSpec & Solid & { helix?: number }} p */
|
|
127
|
+
export function herringbone(p: GearSpec & Solid & {
|
|
128
|
+
helix?: number;
|
|
129
|
+
}): any;
|
|
113
130
|
/** An internal (ring) gear, its rim round it. @param {GearSpec & Solid & { rim?: number }} p */
|
|
114
131
|
export function internal(p: GearSpec & Solid & {
|
|
115
132
|
rim?: number;
|
|
@@ -125,7 +142,7 @@ export function rack(p: GearSpec & Solid & {
|
|
|
125
142
|
* a centre distance checked: closer than needed jams the teeth, further adds backlash.
|
|
126
143
|
* @param {GearModel} a @param {GearModel} b @param {{ centre?: number }} [o]
|
|
127
144
|
*/
|
|
128
|
-
export function mesh(a: GearModel, b: GearModel, { centre }?: {
|
|
145
|
+
export function mesh(a: GearModel, b: GearModel, { centre, width }?: {
|
|
129
146
|
centre?: number;
|
|
130
147
|
}): any;
|
|
131
148
|
/**
|
|
@@ -153,6 +170,146 @@ export function printable(g: GearModel, printer: {
|
|
|
153
170
|
nozzle?: number;
|
|
154
171
|
wall_min?: number;
|
|
155
172
|
}, width?: number): any[];
|
|
173
|
+
/** The Lewis form factor Y for z teeth (20° full depth); Infinity for a rack. @param {number} z */
|
|
174
|
+
export function lewisFactor(z: number): number;
|
|
175
|
+
/**
|
|
176
|
+
* How strong a gear's teeth are by the Lewis equation: the bending stress at the root of a tooth carrying the whole
|
|
177
|
+
* load at its tip, σ = F_t / (b m Y), against the material's strength. Give a torque (N·mm) for the stress and safety
|
|
178
|
+
* factor at it; give a safety factor for the torque the gear carries at it. Helical teeth are read in their normal
|
|
179
|
+
* section (m cos β, z / cos³β teeth). A speed (rpm) adds Barth's velocity factor, (3.05 + V) / 3.05 for a cut (here a
|
|
180
|
+
* printed) profile. A first number: the root fillet and a tooth's neighbours help, a printed tooth's layers and
|
|
181
|
+
* voids hurt. Where it matters, measure it, or analyse the tooth (fea).
|
|
182
|
+
* @param {GearModel} g
|
|
183
|
+
* @param {{ width: number, material: { strength: number, name?: string }, torque?: number, safety?: number, speed?: number }} o
|
|
184
|
+
*/
|
|
185
|
+
export function strength(g: GearModel, o?: {
|
|
186
|
+
width: number;
|
|
187
|
+
material: {
|
|
188
|
+
strength: number;
|
|
189
|
+
name?: string;
|
|
190
|
+
};
|
|
191
|
+
torque?: number;
|
|
192
|
+
safety?: number;
|
|
193
|
+
speed?: number;
|
|
194
|
+
}): {
|
|
195
|
+
Y: number;
|
|
196
|
+
velocity: number;
|
|
197
|
+
force: number;
|
|
198
|
+
torque: number;
|
|
199
|
+
findings: any[];
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* A straight bevel gear's numbers, for a mate of `mate` teeth with the shafts at `shaftAngle` (90° by default): the
|
|
203
|
+
* pitch cone angle δ (tan δ = sin Σ / (z₂/z₁ + cos Σ)), the cone distance R (to the apex along the pitch cone), the
|
|
204
|
+
* virtual teeth z / cos δ of its back cone (Tredgold), and the face width's limit R / 3. Module and diameters at the
|
|
205
|
+
* back (large) end.
|
|
206
|
+
* @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, pressureAngle?: number, backlash?: number }} p
|
|
207
|
+
*/
|
|
208
|
+
export function bevelModel(p: {
|
|
209
|
+
module: number;
|
|
210
|
+
teeth: number;
|
|
211
|
+
mate: number;
|
|
212
|
+
shaftAngle?: number;
|
|
213
|
+
width?: number;
|
|
214
|
+
pressureAngle?: number;
|
|
215
|
+
backlash?: number;
|
|
216
|
+
}): {
|
|
217
|
+
kind: string;
|
|
218
|
+
mate: any;
|
|
219
|
+
shaftAngle: number;
|
|
220
|
+
pitchAngle: number;
|
|
221
|
+
coneDistance: number;
|
|
222
|
+
virtualTeeth: number;
|
|
223
|
+
width: any;
|
|
224
|
+
height: number;
|
|
225
|
+
smallEnd: number;
|
|
226
|
+
module: number;
|
|
227
|
+
teeth: number;
|
|
228
|
+
/**
|
|
229
|
+
* degrees
|
|
230
|
+
*/
|
|
231
|
+
pressureAngle: number;
|
|
232
|
+
/**
|
|
233
|
+
* times the module
|
|
234
|
+
*/
|
|
235
|
+
shift: number;
|
|
236
|
+
/**
|
|
237
|
+
* mm, this gear's share is half
|
|
238
|
+
*/
|
|
239
|
+
backlash: number;
|
|
240
|
+
/**
|
|
241
|
+
* pitch diameter, module × teeth
|
|
242
|
+
*/
|
|
243
|
+
pitch: number;
|
|
244
|
+
/**
|
|
245
|
+
* base circle diameter
|
|
246
|
+
*/
|
|
247
|
+
base: number;
|
|
248
|
+
/**
|
|
249
|
+
* tip diameter
|
|
250
|
+
*/
|
|
251
|
+
tip: number;
|
|
252
|
+
/**
|
|
253
|
+
* root diameter
|
|
254
|
+
*/
|
|
255
|
+
root: number;
|
|
256
|
+
/**
|
|
257
|
+
* tooth thickness on the pitch circle (an arc, mm), less half the backlash
|
|
258
|
+
*/
|
|
259
|
+
thickness: number;
|
|
260
|
+
/**
|
|
261
|
+
* π × module
|
|
262
|
+
*/
|
|
263
|
+
circularPitch: number;
|
|
264
|
+
/**
|
|
265
|
+
* π × module × cos(pressure angle)
|
|
266
|
+
*/
|
|
267
|
+
basePitch: number;
|
|
268
|
+
/**
|
|
269
|
+
* the tooth's width across its tip (mm)
|
|
270
|
+
*/
|
|
271
|
+
topLand: number;
|
|
272
|
+
/**
|
|
273
|
+
* the tooth's width where it meets the root (mm)
|
|
274
|
+
*/
|
|
275
|
+
rootThickness: number;
|
|
276
|
+
/**
|
|
277
|
+
* the basic rack it was drawn from
|
|
278
|
+
*/
|
|
279
|
+
rack: {
|
|
280
|
+
pressureAngle: number;
|
|
281
|
+
addendum: number;
|
|
282
|
+
dedendum: number;
|
|
283
|
+
rootFillet: number;
|
|
284
|
+
tipRound: number;
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* A straight bevel gear: its back (large) end on the bed at z = 0, its axis up z toward the cone's apex, the spur
|
|
289
|
+
* profile of its back end scaled toward the apex up the face width, so every tooth runs straight to the apex and the
|
|
290
|
+
* pitch surface is the cone. (A printable approximation to the octoidal profile: close for teeth of 12 or more.)
|
|
291
|
+
* @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, bore?: number, chamfer?: number }} p
|
|
292
|
+
*/
|
|
293
|
+
export function bevel(p: {
|
|
294
|
+
module: number;
|
|
295
|
+
teeth: number;
|
|
296
|
+
mate: number;
|
|
297
|
+
shaftAngle?: number;
|
|
298
|
+
width?: number;
|
|
299
|
+
bore?: number;
|
|
300
|
+
chamfer?: number;
|
|
301
|
+
}): jscad.geometries.geom3.Geom3;
|
|
302
|
+
/**
|
|
303
|
+
* How two bevel gears mesh: turns of b for one of a, the cone angles (they add to the shaft angle), and the contact
|
|
304
|
+
* ratio of their back cones' equivalent spur gears (Tredgold). @param {object} a @param {object} b the gears' parameters
|
|
305
|
+
*/
|
|
306
|
+
export function bevelMesh(a: object, b: object): {
|
|
307
|
+
ratio: number;
|
|
308
|
+
pitchAngles: number[];
|
|
309
|
+
coneDistance: number;
|
|
310
|
+
contact: any;
|
|
311
|
+
findings: any[];
|
|
312
|
+
};
|
|
156
313
|
/**
|
|
157
314
|
* The defaults, each with the rule it comes from. Coefficients are times the module.
|
|
158
315
|
* @type {Record<string, { value: number, unit: string, rule: string, kind: string }>}
|
|
@@ -163,6 +320,8 @@ export const DEFAULTS: Record<string, {
|
|
|
163
320
|
rule: string;
|
|
164
321
|
kind: string;
|
|
165
322
|
}>;
|
|
323
|
+
export { contact } from "./contact.mjs";
|
|
324
|
+
export { toothStress } from "./tooth.mjs";
|
|
166
325
|
/**
|
|
167
326
|
* width up z; chamfer at the bed face (and the top); bore and flat for a shaft
|
|
168
327
|
*/
|
|
@@ -247,3 +406,5 @@ export type GearModel = {
|
|
|
247
406
|
};
|
|
248
407
|
};
|
|
249
408
|
import jscad from '@jscad/modeling';
|
|
409
|
+
export { planetary, planetaryRatio } from "./planetary.mjs";
|
|
410
|
+
export { wormModel, worm, wormWheel, wormMesh } from "./worm.mjs";
|
package/gears.mjs
CHANGED
|
@@ -52,7 +52,13 @@ function common(what, p) {
|
|
|
52
52
|
const dedendum = between(what, 'dedendum', p.dedendum ?? D('dedendum'), addendum, 2, ' (times the module, at least the addendum)');
|
|
53
53
|
const rootFillet = between(what, 'rootFillet', p.rootFillet ?? D('rootFillet'), 0, 0.6, ' (times the module)');
|
|
54
54
|
const tipRound = between(what, 'tipRound', p.tipRound ?? D('tipRound'), 0, 0.4, ' (times the module)');
|
|
55
|
-
|
|
55
|
+
// Helical teeth: the spur profile turned along the width by the helix angle (the module and pressure angle are the
|
|
56
|
+
// transverse ones, in the gear's own plane, so a helical gear's centre distance is a spur gear's)
|
|
57
|
+
const helix = between(what, 'helix', p.helix ?? 0, 0, 45, '°');
|
|
58
|
+
if (p.hand != null && p.hand !== 'right' && p.hand !== 'left') throw new Error(`${what}: hand is "right" or "left" (got ${shown(p.hand)})`);
|
|
59
|
+
if (p.herringbone != null && typeof p.herringbone !== 'boolean') throw new Error(`${what}: herringbone is true or false (got ${shown(p.herringbone)})`);
|
|
60
|
+
if (p.herringbone && !helix) throw new Error(`${what}: a herringbone needs a helix angle (say helix: 30)`);
|
|
61
|
+
return { module, pressureAngle, shift, backlash, addendum, dedendum, rootFillet, tipRound, helix, hand: p.hand ?? 'right', herringbone: !!p.herringbone };
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
// ---------- the numbers ----------
|
|
@@ -97,6 +103,7 @@ export function gearModel(p) {
|
|
|
97
103
|
const rootHalf = halfAt(s, r, rb, Math.max(rf, rb));
|
|
98
104
|
return {
|
|
99
105
|
kind: 'external', module: m, teeth, pressureAngle, shift: x, backlash,
|
|
106
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
100
107
|
pitch: 2 * r, base: 2 * rb, tip: 2 * ra, root: 2 * rf, thickness: s,
|
|
101
108
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
102
109
|
topLand: 2 * ra * Math.sin(tipHalf), rootThickness: 2 * Math.max(rf, rb) * Math.sin(rootHalf),
|
|
@@ -124,6 +131,7 @@ export function internalModel(p) {
|
|
|
124
131
|
if (!(toothHalf(ra) > 0)) throw new Error(`${what}: the teeth come to a point at the tip circle: less profile shift`);
|
|
125
132
|
return {
|
|
126
133
|
kind: 'internal', module: m, teeth, pressureAngle, shift: x, backlash,
|
|
134
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
127
135
|
pitch: 2 * r, base: 2 * rb, tip: 2 * ra, root: 2 * rf, thickness: s, space: e, rim,
|
|
128
136
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
129
137
|
topLand: 2 * Math.max(ra, rb) * Math.sin(toothHalf(Math.max(ra, rb))), rootThickness: 2 * rf * Math.sin(toothHalf(rf)),
|
|
@@ -147,6 +155,7 @@ export function rackModel(p) {
|
|
|
147
155
|
if (!(tipHalf > 0)) throw new Error(`${what}: the teeth come to a point: a smaller addendum or pressure angle`);
|
|
148
156
|
return {
|
|
149
157
|
kind: 'rack', module: m, teeth, pressureAngle, shift: 0, backlash, height, thickness: s,
|
|
158
|
+
helix: c.helix, hand: c.hand, herringbone: c.herringbone, thrust: c.herringbone ? 0 : Math.tan(c.helix * DEG),
|
|
150
159
|
length: teeth * Math.PI * m, tipLine: m * c.addendum, rootLine: -m * c.dedendum,
|
|
151
160
|
circularPitch: Math.PI * m, basePitch: Math.PI * m * Math.cos(a),
|
|
152
161
|
topLand: 2 * tipHalf, rootThickness: s + 2 * m * c.dedendum * Math.tan(a),
|
|
@@ -244,6 +253,7 @@ function loop({ teeth: z, thickness: s, r, rb, ra, rf, fillet, round, grow = 0 }
|
|
|
244
253
|
flankT: (rho) => -hAt(rho), point: (t, rho) => [rho * Math.cos(t), rho * Math.sin(t)],
|
|
245
254
|
});
|
|
246
255
|
const tooth = [...h.pts, [ra, 0], ...h.pts.slice(1).reverse().map(([x, y]) => [x, -y])];
|
|
256
|
+
if (!Number.isInteger(z)) return { tooth, fillet: h.fillet, round: h.round };
|
|
247
257
|
const out = [];
|
|
248
258
|
for (let k = 0; k < z; k++) {
|
|
249
259
|
const c = Math.cos((TAU * k) / z), sn = Math.sin((TAU * k) / z);
|
|
@@ -315,20 +325,24 @@ export function rackProfile(p, grow = 0) {
|
|
|
315
325
|
|
|
316
326
|
// A solid from loops at heights: each slice is the loops at a height, grown (a chamfer: drawn smaller there) and turned
|
|
317
327
|
// (a helix), all with the same points, so the walls join point to point. Caps are triangulated with their holes.
|
|
318
|
-
function loft(profile, width, { chamfer, twist }) {
|
|
328
|
+
function loft(profile, width, { chamfer, twist, slide, scale }) {
|
|
319
329
|
const [bottom, top] = Array.isArray(chamfer) ? chamfer : [chamfer, 0];
|
|
320
330
|
if (bottom + top >= width) throw new Error(`the chamfers (${bottom} and ${top} mm) are as tall as the gear (${width} mm)`);
|
|
321
331
|
// heights: the chamfers' ends, and for a twist enough between that no slice turns more than a degree or so
|
|
322
332
|
const zs = [0, ...(bottom > 0 ? [bottom] : []), ...(top > 0 ? [width - top] : []), width];
|
|
323
333
|
if (twist) {
|
|
324
|
-
const most = Math.max(...
|
|
334
|
+
const most = Math.max(...[0, 0.25, 0.5, 0.75, 1].map((f) => Math.abs(twist(width * f)))), n = Math.ceil(most / (1.5 * DEG));
|
|
325
335
|
for (let i = 1; i < n; i++) zs.push((width * i) / n);
|
|
336
|
+
zs.push(width / 2); // (a herringbone's apex)
|
|
326
337
|
}
|
|
338
|
+
if (slide) { const n = Math.ceil(width / 0.5); for (let i = 1; i < n; i++) zs.push((width * i) / n); zs.push(width / 2); }
|
|
339
|
+
if (scale) for (let i = 1; i < 8; i++) zs.push((width * i) / 8); // (straight lines toward the apex: a few slices keep the caps' triangles sound)
|
|
327
340
|
const heights = [...new Set(zs.map((z) => +z.toFixed(9)))].sort((x, y) => x - y);
|
|
328
341
|
const slices = heights.map((z) => {
|
|
329
342
|
const grow = z < bottom ? -(bottom - z) : z > width - top ? -(z - (width - top)) : 0;
|
|
330
|
-
const loops = profile(grow), turn = twist ? twist(z) : 0, c = Math.cos(turn), s = Math.sin(turn);
|
|
331
|
-
const
|
|
343
|
+
const loops = profile(grow, z), turn = twist ? twist(z) : 0, k = scale ? scale(z) : 1, c = Math.cos(turn) * k, s = Math.sin(turn) * k, dx = slide ? slide(z) : 0;
|
|
344
|
+
const at = (p) => [p[0] * c - p[1] * s + dx, p[0] * s + p[1] * c];
|
|
345
|
+
const sides = loops.flatMap((pts) => pts.map((p, i) => [at(p), at(pts[(i + 1) % pts.length])]));
|
|
332
346
|
return slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, z]), slice.fromSides(sides));
|
|
333
347
|
});
|
|
334
348
|
return extrudeFromSlices({ numberOfSlices: slices.length, repair: false, callback: (t, i) => slices[i] }, slices[0]);
|
|
@@ -343,22 +357,42 @@ function loft(profile, width, { chamfer, twist }) {
|
|
|
343
357
|
*/
|
|
344
358
|
export function spur(p) {
|
|
345
359
|
const width = size('spur', 'width', p?.width), chamfer = chamfers('spur', p, width);
|
|
346
|
-
spurProfile(p); // (refuses here, before any slicing)
|
|
347
|
-
return loft((grow) => spurProfile(p, grow).loops, width, { chamfer });
|
|
360
|
+
const { model: g } = spurProfile(p); // (refuses here, before any slicing)
|
|
361
|
+
return loft((grow) => spurProfile(p, grow).loops, width, { chamfer, twist: twistOf(g, width) });
|
|
348
362
|
}
|
|
349
363
|
|
|
364
|
+
// How far a helical gear's profile has turned at height z: z tan β / r, the right hand turning anticlockwise up z; a
|
|
365
|
+
// herringbone turns to the middle and back. Gears that mesh outside each other are of opposite hands; a pinion and its
|
|
366
|
+
// ring, or its rack, of the same hand.
|
|
367
|
+
function twistOf(g, width) {
|
|
368
|
+
if (!g.helix) return null;
|
|
369
|
+
const k = (g.hand === 'left' ? -1 : 1) * Math.tan(g.helix * DEG) / (g.pitch / 2);
|
|
370
|
+
return g.herringbone ? (z) => k * Math.min(z, width - z) : (z) => k * z;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** A helical gear: a spur gear's profile turned along its width by the helix angle. Meshes with one of the opposite hand. @param {GearSpec & Solid & { helix: number, hand?: 'right' | 'left' }} p */
|
|
374
|
+
export function helical(p) {
|
|
375
|
+
if (!(p?.helix > 0)) throw new Error(`helical: give a helix angle above 0° (got ${shown(p?.helix)}); 15° to 30° print well`);
|
|
376
|
+
return spur({ ...p, herringbone: false });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** A herringbone gear: helical one way to the middle of its width and back, so it pushes no thrust along its axis and stays on its shaft. Prints with no supports. @param {GearSpec & Solid & { helix?: number }} p */
|
|
380
|
+
export function herringbone(p) { return spur({ ...p, helix: p?.helix ?? 30, herringbone: true }); }
|
|
381
|
+
|
|
350
382
|
/** An internal (ring) gear, its rim round it. @param {GearSpec & Solid & { rim?: number }} p */
|
|
351
383
|
export function internal(p) {
|
|
352
384
|
const width = size('internal', 'width', p?.width), chamfer = chamfers('internal', p, width);
|
|
353
|
-
internalProfile(p);
|
|
354
|
-
return loft((grow) => internalProfile(p, grow).loops, width, { chamfer });
|
|
385
|
+
const { model: g } = internalProfile(p);
|
|
386
|
+
return loft((grow) => internalProfile(p, grow).loops, width, { chamfer, twist: twistOf(g, width) });
|
|
355
387
|
}
|
|
356
388
|
|
|
357
389
|
/** A rack along x, its teeth up +y, its width up z. @param {GearSpec & Solid & { height?: number }} p */
|
|
358
390
|
export function rack(p) {
|
|
359
391
|
const width = size('rack', 'width', p?.width), chamfer = chamfers('rack', p, width);
|
|
360
|
-
rackProfile(p);
|
|
361
|
-
|
|
392
|
+
const { model: g } = rackProfile(p);
|
|
393
|
+
// a helical rack's teeth slide along it with height as its pinion's turn: z tan β, the same hand as the pinion
|
|
394
|
+
const k = g.helix ? (g.hand === 'left' ? -1 : 1) * Math.tan(g.helix * DEG) : 0;
|
|
395
|
+
return loft((grow) => rackProfile(p, grow).loops, width, { chamfer, ...(k ? { slide: g.herringbone ? (z) => k * Math.min(z, width - z) : (z) => k * z } : {}) });
|
|
362
396
|
}
|
|
363
397
|
|
|
364
398
|
function chamfers(what, p, width) {
|
|
@@ -386,14 +420,22 @@ function working(a, sum, zs) {
|
|
|
386
420
|
* a centre distance checked: closer than needed jams the teeth, further adds backlash.
|
|
387
421
|
* @param {GearModel} a @param {GearModel} b @param {{ centre?: number }} [o]
|
|
388
422
|
*/
|
|
389
|
-
export function mesh(a, b, { centre } = {}) {
|
|
423
|
+
export function mesh(a, b, { centre, width } = {}) {
|
|
390
424
|
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
391
425
|
for (const [k, g] of [['a', a], ['b', b]]) if (!g || !['external', 'internal', 'rack'].includes(g.kind)) throw new Error(`mesh: ${k} is a gear's model (gearModel, internalModel or rackModel), not ${shown(g)}`);
|
|
392
426
|
if (a.kind !== 'external' && b.kind !== 'external') throw new Error(`mesh: a ${a.kind} and a ${b.kind} don't mesh: one of them is an outer gear`);
|
|
393
|
-
if (b.kind === 'external' && a.kind !== 'external') return flip(mesh(b, a, { centre }));
|
|
427
|
+
if (b.kind === 'external' && a.kind !== 'external') return flip(mesh(b, a, { centre, width }));
|
|
394
428
|
if (Math.abs(a.module - b.module) > 1e-9) f('fail', `modules differ (${a.module} and ${b.module} mm): teeth of different sizes don't mesh`, 'mesh.module');
|
|
395
429
|
if (Math.abs(a.pressureAngle - b.pressureAngle) > 1e-9) f('fail', `pressure angles differ (${a.pressureAngle}° and ${b.pressureAngle}°): the flanks don't roll on each other`, 'mesh.pressure');
|
|
396
430
|
const m = a.module, al = a.pressureAngle * DEG, pb = Math.PI * m * Math.cos(al);
|
|
431
|
+
// Helical teeth: the same angle, opposite hands outside each other, the same hand on a ring or a rack
|
|
432
|
+
const ha = a.helix ?? 0, hb = b.helix ?? 0;
|
|
433
|
+
if (Math.abs(ha - hb) > 1e-9) f('fail', `helix angles differ (${ha}° and ${hb}°): the teeth cross each other`, 'mesh.helix');
|
|
434
|
+
else if (ha > 0) {
|
|
435
|
+
const same = b.kind !== 'external';
|
|
436
|
+
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');
|
|
437
|
+
if (!!a.herringbone !== !!b.herringbone) f('fail', 'a herringbone meshes only with a herringbone', 'mesh.helix');
|
|
438
|
+
}
|
|
397
439
|
const ra1 = a.tip / 2, rb1 = a.base / 2, r1 = a.pitch / 2;
|
|
398
440
|
let need, ratio, contact, aw = al;
|
|
399
441
|
if (b.kind === 'external') {
|
|
@@ -418,10 +460,14 @@ export function mesh(a, b, { centre } = {}) {
|
|
|
418
460
|
ratio = Math.PI * a.pitch; // mm a turn
|
|
419
461
|
contact = (Math.sqrt(ra1 ** 2 - rb1 ** 2) - r1 * Math.sin(al) + (m * (b.rack.addendum - a.shift)) / Math.sin(al)) / pb;
|
|
420
462
|
}
|
|
463
|
+
// the overlap ratio: how far a tooth's own twist carries the contact on across the width (εβ = b tan β / π m, each
|
|
464
|
+
// half of a herringbone on its own)
|
|
465
|
+
const overlap = ha > 0 && width !== undefined ? ((a.herringbone ? width / 2 : width) * Math.tan(ha * DEG)) / (Math.PI * m) : 0;
|
|
466
|
+
if (overlap) contact += overlap;
|
|
421
467
|
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'}`;
|
|
422
468
|
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 });
|
|
423
469
|
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 });
|
|
424
|
-
else f('pass', `contact ratio ${fmt(contact)}: ${fmt(contact)} pairs of teeth share the load on average`, 'mesh.contact', { contact });
|
|
470
|
+
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 });
|
|
425
471
|
let backlash = a.backlash / 2 + b.backlash / 2;
|
|
426
472
|
if (centre !== undefined) {
|
|
427
473
|
if (!isNum(centre)) throw new Error(`mesh: centre is a distance in mm (got ${shown(centre)})`);
|
|
@@ -429,11 +475,16 @@ export function mesh(a, b, { centre } = {}) {
|
|
|
429
475
|
// 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
|
|
430
476
|
const added = 2 * off * Math.tan(aw);
|
|
431
477
|
backlash += added;
|
|
432
|
-
|
|
478
|
+
// closer than they need eats the backlash (2 Δa tan αw of it) and the clearance under the tips (0.25 m); past
|
|
479
|
+
// either, the teeth jam
|
|
480
|
+
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;
|
|
481
|
+
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 });
|
|
482
|
+
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 });
|
|
433
483
|
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 });
|
|
434
|
-
else f('pass', `centre distance ${fmt(centre, 3)} mm,
|
|
484
|
+
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 });
|
|
435
485
|
}
|
|
436
|
-
|
|
486
|
+
const thrust = a.herringbone || !ha ? 0 : Math.tan(ha * DEG);
|
|
487
|
+
return { kind: b.kind, centre: need, ratio, contact, overlap, thrust, pressureAngle: aw / DEG, backlash, text: sense, findings: out };
|
|
437
488
|
}
|
|
438
489
|
const flip = (r) => ({ ...r, ratio: r.kind === 'rack' ? r.ratio : 1 / r.ratio });
|
|
439
490
|
const fmt = (x, d = 2) => String(+x.toFixed(d));
|
|
@@ -490,9 +541,142 @@ export function printable(g, printer, width) {
|
|
|
490
541
|
if (g.rootThickness < least - 1e-9) f('fail', `a tooth is ${fmt(g.rootThickness)} mm across at its root, under the thinnest wall (${fmt(least)} mm): a larger module`, 'gear.root', rootAt);
|
|
491
542
|
else f('pass', `a tooth is ${fmt(g.rootThickness)} mm across at its root, ${fmt(rootLines, 1)} lines`, 'gear.root', rootAt);
|
|
492
543
|
if (g.topLand < line) f('warn', `the tips are ${fmt(g.topLand)} mm across, under a line (${line} mm): they print as one bead, rounded off; fine for meshing, but don't count on the tip`, 'gear.tip', tipAt);
|
|
544
|
+
if (g.helix > 0) {
|
|
545
|
+
// the flank leans most at the tip: tan β_a = tan β × r_a / r
|
|
546
|
+
const ra = g.kind === 'rack' ? 1 : g.tip / (g.kind === 'internal' ? g.root : g.pitch), lean = Math.atan(Math.tan(g.helix * DEG) * Math.max(1, ra)) / DEG;
|
|
547
|
+
if (lean > 45) f('warn', `the teeth lean ${fmt(lean, 1)}° from upright at their tips: past 45° the flanks sag as they print; a smaller helix angle`, 'gear.helix', tipAt);
|
|
548
|
+
else f('pass', `the teeth lean ${fmt(lean, 1)}° from upright at their tips: prints with no supports`, 'gear.helix');
|
|
549
|
+
if (!g.herringbone) f('info', `a helix of ${g.helix}° pushes ${fmt(Math.tan(g.helix * DEG), 2)} N along the axis for each newton it drives: hold the gear on its shaft, or make it a herringbone`, 'gear.thrust');
|
|
550
|
+
}
|
|
493
551
|
if (width !== undefined) {
|
|
494
552
|
const layers = width / layer;
|
|
495
553
|
if (Math.abs(layers - Math.round(layers)) > 0.05) f('warn', `${width} mm wide is ${fmt(layers)} layers of ${layer} mm: a whole number prints as drawn`, 'gear.layers');
|
|
496
554
|
}
|
|
497
555
|
return out;
|
|
498
556
|
}
|
|
557
|
+
|
|
558
|
+
// Planetary gearboxes: the teeth for a ratio, laid out in phase
|
|
559
|
+
export { planetary, planetaryRatio } from './planetary.mjs';
|
|
560
|
+
// The mesh measured from the drawn teeth: backlash, transmission error, interference
|
|
561
|
+
export { contact } from './contact.mjs';
|
|
562
|
+
// A tooth's root stress by finite elements
|
|
563
|
+
export { toothStress } from './tooth.mjs';
|
|
564
|
+
// Worms and their wheels
|
|
565
|
+
export { wormModel, worm, wormWheel, wormMesh } from './worm.mjs';
|
|
566
|
+
|
|
567
|
+
// ---------- strength ----------
|
|
568
|
+
|
|
569
|
+
// The Lewis form factor for 20° full-depth teeth, by number of teeth (Budynas and Nisbett, Shigley's Mechanical
|
|
570
|
+
// Engineering Design, 10th ed., Table 14-2); a rack is 0.485. Between rows, read along a straight line.
|
|
571
|
+
const LEWIS = [[12, 0.245], [13, 0.261], [14, 0.277], [15, 0.290], [16, 0.296], [17, 0.303], [18, 0.309], [19, 0.314], [20, 0.322], [21, 0.328], [22, 0.331], [24, 0.337], [26, 0.346], [28, 0.353], [30, 0.359], [34, 0.371], [38, 0.384], [43, 0.397], [50, 0.409], [60, 0.422], [75, 0.435], [100, 0.447], [150, 0.460], [300, 0.472], [400, 0.480]];
|
|
572
|
+
/** The Lewis form factor Y for z teeth (20° full depth); Infinity for a rack. @param {number} z */
|
|
573
|
+
export function lewisFactor(z) {
|
|
574
|
+
if (z === Infinity) return 0.485;
|
|
575
|
+
if (z <= LEWIS[0][0]) return LEWIS[0][1];
|
|
576
|
+
if (z >= LEWIS.at(-1)[0]) return LEWIS.at(-1)[1] + ((0.485 - LEWIS.at(-1)[1]) * (1 - 400 / z));
|
|
577
|
+
const i = LEWIS.findIndex(([n]) => n >= z), [n0, y0] = LEWIS[i - 1], [n1, y1] = LEWIS[i];
|
|
578
|
+
return y0 + ((y1 - y0) * (z - n0)) / (n1 - n0);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* How strong a gear's teeth are by the Lewis equation: the bending stress at the root of a tooth carrying the whole
|
|
583
|
+
* load at its tip, σ = F_t / (b m Y), against the material's strength. Give a torque (N·mm) for the stress and safety
|
|
584
|
+
* factor at it; give a safety factor for the torque the gear carries at it. Helical teeth are read in their normal
|
|
585
|
+
* section (m cos β, z / cos³β teeth). A speed (rpm) adds Barth's velocity factor, (3.05 + V) / 3.05 for a cut (here a
|
|
586
|
+
* printed) profile. A first number: the root fillet and a tooth's neighbours help, a printed tooth's layers and
|
|
587
|
+
* voids hurt. Where it matters, measure it, or analyse the tooth (fea).
|
|
588
|
+
* @param {GearModel} g
|
|
589
|
+
* @param {{ width: number, material: { strength: number, name?: string }, torque?: number, safety?: number, speed?: number }} o
|
|
590
|
+
*/
|
|
591
|
+
export function strength(g, o = {}) {
|
|
592
|
+
if (!g || !['external', 'internal', 'rack'].includes(g.kind)) throw new Error(`strength: give a gear's model, not ${shown(g)}`);
|
|
593
|
+
const width = size('strength', 'width', o.width), sigma = o.material?.strength;
|
|
594
|
+
if (!(isNum(sigma) && sigma > 0)) throw new Error(`strength: the material needs a strength above 0 MPa (got ${shown(sigma)})`);
|
|
595
|
+
if (o.torque !== undefined) size('strength', 'torque', o.torque);
|
|
596
|
+
const safety = o.safety === undefined ? 2 : size('strength', 'safety', o.safety);
|
|
597
|
+
const beta = (g.helix ?? 0) * DEG, mn = g.module * Math.cos(beta);
|
|
598
|
+
const teeth = g.kind === 'rack' ? Infinity : g.teeth / Math.cos(beta) ** 3;
|
|
599
|
+
// an internal gear's teeth are stouter at the root than an outer gear's of as many teeth: read as a rack's, a little kind
|
|
600
|
+
const Y = g.kind === 'internal' ? lewisFactor(Infinity) : lewisFactor(teeth);
|
|
601
|
+
const r = g.kind === 'rack' ? null : g.pitch / 2;
|
|
602
|
+
const V = o.speed !== undefined && r ? (size('strength', 'speed', o.speed) * 2 * Math.PI * r) / 60000 : 0, Kv = (3.05 + V) / 3.05;
|
|
603
|
+
const perNewton = Kv / (width * mn * Y); // MPa for each newton at the pitch circle
|
|
604
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
605
|
+
const name = o.material.name ?? 'the material';
|
|
606
|
+
const result = { Y, velocity: Kv, force: (sigma / safety) / perNewton, torque: r ? ((sigma / safety) / perNewton) * r : null, findings: out };
|
|
607
|
+
if (o.torque !== undefined) {
|
|
608
|
+
if (!r) throw new Error('strength: a rack takes a force, not a torque (the torque is its pinion\'s)');
|
|
609
|
+
const F = o.torque / r, stress = F * perNewton, n = sigma / stress;
|
|
610
|
+
Object.assign(result, { stress, safety: n });
|
|
611
|
+
f(n >= safety ? 'pass' : n >= 1 ? 'warn' : 'fail', `at ${fmt(o.torque / 1000, 3)} N·m the teeth see ${fmt(stress, 1)} MPa at their roots (Lewis, Y ${fmt(Y, 3)}${Kv > 1 ? `, ×${fmt(Kv, 2)} for speed` : ''}): ${fmt(n, 1)}× under ${name}'s ${sigma} MPa${n >= safety ? '' : n >= 1 ? `, under the ${safety}× asked` : ': they break'}`, 'gear.strength', { stress, safety: n });
|
|
612
|
+
} else if (r) f('info', `the teeth carry ${fmt(result.torque / 1000, 3)} N·m at ${safety}× under ${name}'s ${sigma} MPa (Lewis, Y ${fmt(Y, 3)})`, 'gear.strength', { torque: result.torque });
|
|
613
|
+
return result;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// ---------- bevel gears ----------
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* A straight bevel gear's numbers, for a mate of `mate` teeth with the shafts at `shaftAngle` (90° by default): the
|
|
620
|
+
* pitch cone angle δ (tan δ = sin Σ / (z₂/z₁ + cos Σ)), the cone distance R (to the apex along the pitch cone), the
|
|
621
|
+
* virtual teeth z / cos δ of its back cone (Tredgold), and the face width's limit R / 3. Module and diameters at the
|
|
622
|
+
* back (large) end.
|
|
623
|
+
* @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, pressureAngle?: number, backlash?: number }} p
|
|
624
|
+
*/
|
|
625
|
+
export function bevelModel(p) {
|
|
626
|
+
const what = 'bevelModel', c = common(what, p), z = whole(what, 'teeth', p?.teeth, 6), mate = whole(what, 'mate', p?.mate, 6);
|
|
627
|
+
const sigma = between(what, 'shaftAngle', p.shaftAngle ?? 90, 30, 150, '°') * DEG, a = c.pressureAngle * DEG;
|
|
628
|
+
const delta = Math.atan2(Math.sin(sigma), mate / z + Math.cos(sigma)), d = c.module * z, R = d / (2 * Math.sin(delta));
|
|
629
|
+
const virtual = z / Math.cos(delta);
|
|
630
|
+
const need = c.addendum - (virtual * Math.sin(a) ** 2) / 2;
|
|
631
|
+
if (c.shift < need - 0.01) throw new Error(`${what}: ${z} teeth on a ${(delta / DEG).toFixed(1)}° cone are undercut (as ${virtual.toFixed(1)} on their back cone): give a profile shift of at least ${(Math.ceil(need * 100) / 100).toFixed(2)}, or more teeth`);
|
|
632
|
+
const width = p.width === undefined ? R / 3 : size(what, 'width', p.width);
|
|
633
|
+
if (width > R / 3 + 1e-9) throw new Error(`${what}: a face width of ${width} mm is over a third of the cone distance (${(R / 3).toFixed(2)} mm): the small end's teeth get too small to carry anything`);
|
|
634
|
+
const g = gearModel({ ...p, teeth: z, helix: 0 });
|
|
635
|
+
return { ...g, kind: 'bevel', mate, shaftAngle: sigma / DEG, pitchAngle: delta / DEG, coneDistance: R, virtualTeeth: virtual, width, height: width * Math.cos(delta), smallEnd: 1 - width / R };
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* A straight bevel gear: its back (large) end on the bed at z = 0, its axis up z toward the cone's apex, the spur
|
|
640
|
+
* profile of its back end scaled toward the apex up the face width, so every tooth runs straight to the apex and the
|
|
641
|
+
* pitch surface is the cone. (A printable approximation to the octoidal profile: close for teeth of 12 or more.)
|
|
642
|
+
* @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, bore?: number, chamfer?: number }} p
|
|
643
|
+
*/
|
|
644
|
+
export function bevel(p) {
|
|
645
|
+
const g = bevelModel(p), h = g.height, H = g.coneDistance * Math.cos(g.pitchAngle * DEG), scale = (z) => 1 - z / H;
|
|
646
|
+
const chamfer = chamfers('bevel', { ...p, chamfer: p.chamfer ?? 0 }, h);
|
|
647
|
+
if (p.bore != null && !(size('bevel', 'bore', p.bore) < g.root * g.smallEnd - 4 * g.module * g.smallEnd)) throw new Error(`bevel: a bore of ${p.bore} mm leaves under two modules of web under the small end's teeth`);
|
|
648
|
+
return loft((grow, z) => [bevelSection(g, grow), ...(p.bore != null ? [reversed(bore(p.bore, p.flat, -grow)).map(([x, y]) => [x / scale(z), y / scale(z)])] : [])], h, { chamfer, scale });
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// A bevel gear's section across its axis at its back end, by Tredgold's construction: the tooth drawn on the back
|
|
652
|
+
// cone, developed flat as a spur gear of z / cos δ teeth; wrapped back onto the back cone (heights along its slant,
|
|
653
|
+
// angles × 1 / cos δ); then seen from the apex onto the plane of the back end's pitch circle. Every section nearer the
|
|
654
|
+
// apex is this one scaled toward the axis, the teeth running straight to the apex.
|
|
655
|
+
function bevelSection(g, grow = 0) {
|
|
656
|
+
const d = g.pitchAngle * DEG, m = g.module, zv = g.virtualTeeth, a = g.pressureAngle * DEG;
|
|
657
|
+
const rv = (m * zv) / 2, r = g.pitch / 2, H = r / Math.tan(d); // the developed pitch radius; the apex over the pitch circle
|
|
658
|
+
const { tooth } = loop({ teeth: zv, thickness: g.thickness, r: rv, rb: rv * Math.cos(a), ra: rv + m * (g.rack.addendum + g.shift), rf: rv - m * (g.rack.dedendum - g.shift), fillet: g.rack.rootFillet * m, round: g.rack.tipRound * m, grow });
|
|
659
|
+
const mapped = tooth.map(([x, y]) => {
|
|
660
|
+
const rho = Math.hypot(x, y), phi = Math.atan2(y, x) / Math.cos(d); // along the back cone's slant from its apex; round the axis
|
|
661
|
+
const q = rho * Math.cos(d), zq = -r * Math.tan(d) + rho * Math.sin(d); // on the back cone: radius, height
|
|
662
|
+
const k = q * (H / (H - zq)); // seen from the apex, on the plane z = 0
|
|
663
|
+
return [k * Math.cos(phi), k * Math.sin(phi)];
|
|
664
|
+
});
|
|
665
|
+
const out = [];
|
|
666
|
+
for (let i = 0; i < g.teeth; i++) { const c = Math.cos((TAU * i) / g.teeth), s = Math.sin((TAU * i) / g.teeth); for (const [x, y] of mapped) out.push([x * c - y * s, x * s + y * c]); }
|
|
667
|
+
return out;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* How two bevel gears mesh: turns of b for one of a, the cone angles (they add to the shaft angle), and the contact
|
|
672
|
+
* ratio of their back cones' equivalent spur gears (Tredgold). @param {object} a @param {object} b the gears' parameters
|
|
673
|
+
*/
|
|
674
|
+
export function bevelMesh(a, b) {
|
|
675
|
+
const ga = bevelModel({ ...a, mate: b.teeth }), gb = bevelModel({ ...b, mate: a.teeth });
|
|
676
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
677
|
+
if (Math.abs(ga.shaftAngle - gb.shaftAngle) > 1e-9) f('fail', `shaft angles differ (${ga.shaftAngle}° and ${gb.shaftAngle}°)`, 'mesh.bevel');
|
|
678
|
+
const virtual = (g) => gearModel({ module: g.module, teeth: Math.max(6, Math.round(g.virtualTeeth)), shift: Math.max(g.shift, 0), pressureAngle: g.pressureAngle });
|
|
679
|
+
const back = mesh(virtual(ga), virtual(gb));
|
|
680
|
+
for (const x of back.findings) out.push({ ...x, text: `on the back cones: ${x.text}` });
|
|
681
|
+
return { ratio: ga.teeth / gb.teeth, pitchAngles: [ga.pitchAngle, gb.pitchAngle], coneDistance: ga.coneDistance, contact: back.contact, findings: out };
|
|
682
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/gears",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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": {
|
|
@@ -15,8 +15,16 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"gears.mjs",
|
|
18
|
+
"planetary.mjs",
|
|
19
|
+
"contact.mjs",
|
|
20
|
+
"tooth.mjs",
|
|
21
|
+
"worm.mjs",
|
|
18
22
|
"diagram.mjs",
|
|
19
23
|
"gears.d.mts",
|
|
24
|
+
"planetary.d.mts",
|
|
25
|
+
"contact.d.mts",
|
|
26
|
+
"tooth.d.mts",
|
|
27
|
+
"worm.d.mts",
|
|
20
28
|
"diagram.d.mts",
|
|
21
29
|
"README.md",
|
|
22
30
|
"LICENSE"
|
|
@@ -49,5 +57,8 @@
|
|
|
49
57
|
"peerDependencies": {
|
|
50
58
|
"@jscad/modeling": "^2.12.0"
|
|
51
59
|
},
|
|
52
|
-
"types": "./gears.d.mts"
|
|
60
|
+
"types": "./gears.d.mts",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@rulecad/fea": "^0.2.9"
|
|
63
|
+
}
|
|
53
64
|
}
|
package/planetary.d.mts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns of the input for one of the output, with one member held: the planetary's ratio, by Willis's relation.
|
|
3
|
+
* @param {{ sun: number, ring: number }} teeth @param {{ held: string, input: string, output: string }} how
|
|
4
|
+
*/
|
|
5
|
+
export function planetaryRatio({ sun: S, ring: R }: {
|
|
6
|
+
sun: number;
|
|
7
|
+
ring: number;
|
|
8
|
+
}, { held, input, output }: {
|
|
9
|
+
held: string;
|
|
10
|
+
input: string;
|
|
11
|
+
output: string;
|
|
12
|
+
}): number;
|
|
13
|
+
/**
|
|
14
|
+
* Teeth for a planetary gearbox: the sets that put together, nearest the wanted ratio first (then the smallest).
|
|
15
|
+
* @param {{ module: number, ratio: number, planets?: number, held?: 'sun' | 'carrier' | 'ring', input?: 'sun' | 'carrier' | 'ring',
|
|
16
|
+
* output?: 'sun' | 'carrier' | 'ring', size?: number, least?: number, most?: number, pressureAngle?: number, backlash?: number }} spec
|
|
17
|
+
* size: the most the ring's rim may be across (mm); least: the fewest teeth on the sun and planets (17 at 20°, so none is undercut)
|
|
18
|
+
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
19
|
+
*/
|
|
20
|
+
export function planetary(spec: {
|
|
21
|
+
module: number;
|
|
22
|
+
ratio: number;
|
|
23
|
+
planets?: number;
|
|
24
|
+
held?: "sun" | "carrier" | "ring";
|
|
25
|
+
input?: "sun" | "carrier" | "ring";
|
|
26
|
+
output?: "sun" | "carrier" | "ring";
|
|
27
|
+
size?: number;
|
|
28
|
+
least?: number;
|
|
29
|
+
most?: number;
|
|
30
|
+
pressureAngle?: number;
|
|
31
|
+
backlash?: number;
|
|
32
|
+
}): {
|
|
33
|
+
best: object;
|
|
34
|
+
others: object[];
|
|
35
|
+
findings: object[];
|
|
36
|
+
};
|
package/planetary.mjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Planetary gearboxes: a sun in the middle, planets round it on a carrier, and a ring round them all. Hold one of the
|
|
2
|
+
// three and the other two turn at a ratio set by the teeth alone (Willis: (ω_sun − ω_carrier) / (ω_ring − ω_carrier) =
|
|
3
|
+
// −R / S). planetary() finds the teeth for a wanted ratio that also put together: the ring is the sun and two planets
|
|
4
|
+
// across (R = S + 2P), the planets go in evenly spaced ((S + R) a whole number of times the planets), and they clear
|
|
5
|
+
// each other. It lays the gearbox out with every planet in phase with the sun and the ring.
|
|
6
|
+
import { gearModel, internalModel, mesh, phase } from './gears.mjs';
|
|
7
|
+
|
|
8
|
+
const DEG = Math.PI / 180;
|
|
9
|
+
const MEMBERS = ['sun', 'carrier', 'ring'];
|
|
10
|
+
const fmt = (x, d = 3) => String(+x.toFixed(d));
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Turns of the input for one of the output, with one member held: the planetary's ratio, by Willis's relation.
|
|
14
|
+
* @param {{ sun: number, ring: number }} teeth @param {{ held: string, input: string, output: string }} how
|
|
15
|
+
*/
|
|
16
|
+
export function planetaryRatio({ sun: S, ring: R }, { held, input, output }) {
|
|
17
|
+
// ω for each member with the held one at 0, from ω_s − ω_c = −(R/S)(ω_r − ω_c)
|
|
18
|
+
const w = held === 'ring' ? { ring: 0, carrier: 1, sun: 1 + R / S } : held === 'carrier' ? { carrier: 0, ring: 1, sun: -R / S } : { sun: 0, carrier: 1, ring: (R + S) / R };
|
|
19
|
+
return w[input] / w[output];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Teeth for a planetary gearbox: the sets that put together, nearest the wanted ratio first (then the smallest).
|
|
24
|
+
* @param {{ module: number, ratio: number, planets?: number, held?: 'sun' | 'carrier' | 'ring', input?: 'sun' | 'carrier' | 'ring',
|
|
25
|
+
* output?: 'sun' | 'carrier' | 'ring', size?: number, least?: number, most?: number, pressureAngle?: number, backlash?: number }} spec
|
|
26
|
+
* size: the most the ring's rim may be across (mm); least: the fewest teeth on the sun and planets (17 at 20°, so none is undercut)
|
|
27
|
+
* @returns {{ best: object, others: object[], findings: object[] }}
|
|
28
|
+
*/
|
|
29
|
+
export function planetary(spec) {
|
|
30
|
+
const what = 'planetary';
|
|
31
|
+
if (!spec || typeof spec !== 'object') throw new Error(`${what}: give it { module, ratio, planets, held, input, output }`);
|
|
32
|
+
const { module: m, ratio } = spec, n = spec.planets ?? 3, held = spec.held ?? 'ring', input = spec.input ?? 'sun';
|
|
33
|
+
if (!(typeof m === 'number' && m > 0)) throw new Error(`${what}: module is a size above 0 (got ${JSON.stringify(m)})`);
|
|
34
|
+
if (!(typeof ratio === 'number' && Number.isFinite(ratio) && ratio !== 0)) throw new Error(`${what}: ratio is turns of the input for one of the output, a number (got ${JSON.stringify(ratio)})`);
|
|
35
|
+
if (!(Number.isInteger(n) && n >= 2 && n <= 8)) throw new Error(`${what}: planets is a whole number from 2 to 8 (got ${JSON.stringify(n)})`);
|
|
36
|
+
for (const [k, v] of [['held', held], ['input', input]]) if (!MEMBERS.includes(v)) throw new Error(`${what}: ${k} is one of ${MEMBERS.join(', ')} (got ${JSON.stringify(v)})`);
|
|
37
|
+
const output = spec.output ?? MEMBERS.find((x) => x !== held && x !== input);
|
|
38
|
+
if (!MEMBERS.includes(output) || new Set([held, input, output]).size !== 3) throw new Error(`${what}: held, input and output are the sun, the carrier and the ring, one each (got ${held}, ${input}, ${output})`);
|
|
39
|
+
const least = spec.least ?? 17, most = spec.most ?? 150, pa = spec.pressureAngle ?? 20;
|
|
40
|
+
const common = { module: m, pressureAngle: pa, ...(spec.backlash != null ? { backlash: spec.backlash } : {}) };
|
|
41
|
+
// Every set that puts together, scored by how near its ratio is
|
|
42
|
+
const sets = [];
|
|
43
|
+
for (let S = least; S <= most; S++) for (let P = least; P <= most; P++) {
|
|
44
|
+
const R = S + 2 * P;
|
|
45
|
+
if ((S + R) % n) continue; // the planets go in evenly spaced
|
|
46
|
+
if (R - P < 12) continue; // a ring at least 12 teeth more than its planets, or their tips foul (KHK)
|
|
47
|
+
const a = (m * (S + P)) / 2, tip = m * (P + 2);
|
|
48
|
+
if (n > 1 && 2 * a * Math.sin(Math.PI / n) < tip + m) continue; // the planets' tips a module apart
|
|
49
|
+
const rim = m * (R + 2.5) + 6 * m;
|
|
50
|
+
if (spec.size != null && rim > spec.size) continue;
|
|
51
|
+
const i = planetaryRatio({ sun: S, ring: R }, { held, input, output });
|
|
52
|
+
sets.push({ sun: S, planet: P, ring: R, ratio: i, off: Math.abs(i - ratio) / Math.abs(ratio), rim });
|
|
53
|
+
}
|
|
54
|
+
if (!sets.length) throw new Error(`${what}: no teeth put together${spec.size != null ? ` within a rim of ${spec.size} mm` : ''} with ${n} planets of ${least} teeth or more: a larger size, fewer planets, or a smaller module`);
|
|
55
|
+
sets.sort((x, y) => x.off - y.off || x.rim - y.rim);
|
|
56
|
+
const best = layout(sets[0], { n, m, common, held, input, output });
|
|
57
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
58
|
+
const off = sets[0].off;
|
|
59
|
+
f(off < 0.005 ? 'pass' : off < 0.05 ? 'warn' : 'fail', `${fmt(best.ratio)} : 1 (${input} to ${output}, ${held} held), ${off < 0.005 ? 'as asked' : `${fmt(off * 100, 1)}% from the ${fmt(ratio)} asked: the nearest that puts together`}: sun ${best.sun.teeth}, planets ${best.planet.teeth} × ${n}, ring ${best.ring.teeth}`, 'planetary.ratio', { ratio: best.ratio, asked: ratio });
|
|
60
|
+
for (const [pair, ms] of [['sun and planet', best.sunMesh], ['planet and ring', best.ringMesh]]) for (const x of ms.findings) out.push({ ...x, text: `${pair}: ${x.text}` });
|
|
61
|
+
return { best, others: sets.slice(1, 6).map((x) => ({ sun: x.sun, planet: x.planet, ring: x.ring, ratio: x.ratio, rim: x.rim })), findings: out };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The gearbox laid out: the sun at the centre, its first tooth on +x; each planet at its place round the carrier,
|
|
65
|
+
// turned so a tooth sits in a gap of the sun and of the ring; the ring turned to suit
|
|
66
|
+
function layout({ sun: S, planet: P, ring: R, ratio }, { n, m, common, held, input, output }) {
|
|
67
|
+
const sun = gearModel({ ...common, teeth: S }), planet = gearModel({ ...common, teeth: P }), ring = internalModel({ ...common, teeth: R });
|
|
68
|
+
const sunMesh = mesh(sun, planet), ringMesh = mesh(planet, ring), a = sunMesh.centre;
|
|
69
|
+
const planets = Array.from({ length: n }, (_, k) => {
|
|
70
|
+
const at = (360 * k) / n;
|
|
71
|
+
return { at: [a * Math.cos(at * DEG), a * Math.sin(at * DEG)], angle: phase(sun, planet, at), place: at };
|
|
72
|
+
});
|
|
73
|
+
// the ring, from the first planet: the line from that planet to the ring's centre points back along 180°
|
|
74
|
+
const ringAngle = (P / R) * planets[0].angle + phase(planet, ring, 180);
|
|
75
|
+
return { sun: { teeth: S, model: sun }, planet: { teeth: P, model: planet }, ring: { teeth: R, model: ring, angle: ringAngle },
|
|
76
|
+
planets, centre: a, ratio, held, input, output, rim: ring.rim, module: m, sunMesh, ringMesh };
|
|
77
|
+
}
|
package/tooth.d.mts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tooth's root stress by finite elements, at a torque on the gear.
|
|
3
|
+
* @param {object} p the gear's parameters (as gearModel takes them)
|
|
4
|
+
* @param {{ width: number, torque: number, material: { E: number, nu: number, strength?: number, name?: string }, cells?: number }} o
|
|
5
|
+
* cells: across a module (16)
|
|
6
|
+
*/
|
|
7
|
+
export function toothStress(p: object, { width, torque, material, cells }?: {
|
|
8
|
+
width: number;
|
|
9
|
+
torque: number;
|
|
10
|
+
material: {
|
|
11
|
+
E: number;
|
|
12
|
+
nu: number;
|
|
13
|
+
strength?: number;
|
|
14
|
+
name?: string;
|
|
15
|
+
};
|
|
16
|
+
cells?: number;
|
|
17
|
+
}): {
|
|
18
|
+
peak: number;
|
|
19
|
+
at: number[];
|
|
20
|
+
lewis: number;
|
|
21
|
+
ratio: number;
|
|
22
|
+
cells: number[];
|
|
23
|
+
change: number;
|
|
24
|
+
findings: any[];
|
|
25
|
+
};
|
package/tooth.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// One tooth analysed: the tooth and a slice of rim under it as a flat part of finite elements (@rulecad/fea, plane
|
|
2
|
+
// stress), the rim's cut edges held, the load at the tip along the line of action. The peak stress at the root, with
|
|
3
|
+
// the fillet and the printed shape as they are, against Lewis's number, which leaves the fillet's concentration out.
|
|
4
|
+
import { grid, analyse, positions } from '@rulecad/fea';
|
|
5
|
+
import { gearModel, spurProfile, lewisFactor } from './gears.mjs';
|
|
6
|
+
|
|
7
|
+
const fmt = (x, d = 1) => String(+x.toFixed(d));
|
|
8
|
+
const inside = ([x, y], pts) => { let c = false; for (let i = 0, j = pts.length - 1; i < pts.length; j = i++) { const [xi, yi] = pts[i], [xj, yj] = pts[j]; if ((yi > y) !== (yj > y) && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) c = !c; } return c; };
|
|
9
|
+
const toSeg = ([px, py], [ax, ay], [bx, by]) => { const dx = bx - ax, dy = by - ay, t = Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / (dx * dx + dy * dy || 1))); return Math.hypot(px - ax - t * dx, py - ay - t * dy); };
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A tooth's root stress by finite elements, at a torque on the gear.
|
|
13
|
+
* @param {object} p the gear's parameters (as gearModel takes them)
|
|
14
|
+
* @param {{ width: number, torque: number, material: { E: number, nu: number, strength?: number, name?: string }, cells?: number }} o
|
|
15
|
+
* cells: across a module (16)
|
|
16
|
+
*/
|
|
17
|
+
export function toothStress(p, { width, torque, material, cells = 32 } = {}) {
|
|
18
|
+
const fine = solveTooth(p, { width, torque, material, cells }), coarse = solveTooth(p, { width, torque, material, cells: Math.round(cells * 0.75) });
|
|
19
|
+
const change = fine.peak / coarse.peak - 1, out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
20
|
+
const { peak, lewis, h, nx, ny, atRoot } = fine, name = material.name ?? 'the material', n = material.strength ? material.strength / peak : null;
|
|
21
|
+
f(n == null ? 'info' : n >= 2 ? 'pass' : n >= 1 ? 'warn' : 'fail', `a tooth analysed (${nx} × ${ny} cells of ${fmt(h, 3)} mm): ${fmt(peak)} MPa at the root of its loaded side, ${fmt(atRoot, 2)} mm above the root circle, ${fmt(peak / lewis, 2)}× Lewis's ${fmt(lewis)} MPa (the fillet's concentration)${n == null ? '' : n >= 1 ? `: ${fmt(n)}× under ${name}'s ${material.strength} MPa` : `: over ${name}'s ${material.strength} MPa, it breaks`}`, 'gear.fe', { peak, lewis });
|
|
22
|
+
if (Math.abs(change) > 0.05) f('warn', `the peak changed ${fmt(change * 100)}% from cells a third bigger: not settled; more cells`, 'gear.fe.coarse', { change });
|
|
23
|
+
return { peak, at: fine.at, lewis, ratio: peak / lewis, cells: [nx, ny], change, findings: out };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function solveTooth(p, { width, torque, material, cells }) {
|
|
27
|
+
const g = gearModel(p), m = g.module, z = g.teeth, a = (g.pressureAngle * Math.PI) / 180;
|
|
28
|
+
if (!(width > 0) || !(torque > 0)) throw new Error(`toothStress: width and torque are sizes above 0 (got ${width} and ${torque})`);
|
|
29
|
+
if (!(material?.E > 0)) throw new Error('toothStress: the material needs a modulus E (MPa) and a Poisson\'s ratio nu');
|
|
30
|
+
// the tooth on +x between the middles of its spaces, and the rim under it two and a half modules deep
|
|
31
|
+
const loop = spurProfile(p).loops[0], half = Math.PI / z, rf = g.root / 2, rr = rf - 2.5 * m;
|
|
32
|
+
const tooth = loop.filter(([x, y]) => Math.abs(Math.atan2(y, x)) <= half + 1e-9 && x > 0).sort((u, v) => Math.atan2(u[1], u[0]) - Math.atan2(v[1], v[0]));
|
|
33
|
+
const arc = Array.from({ length: 13 }, (_, i) => { const t = half - (2 * half * i) / 12; return [rr * Math.cos(t), rr * Math.sin(t)]; });
|
|
34
|
+
const poly = [...tooth, ...arc];
|
|
35
|
+
// a grid over it, each cell as much solid as its 3 × 3 samples say
|
|
36
|
+
const h = m / cells, x0 = Math.min(...poly.map((q) => q[0])), y0 = Math.min(...poly.map((q) => q[1]));
|
|
37
|
+
const nx = Math.ceil((Math.max(...poly.map((q) => q[0])) - x0) / h), ny = Math.ceil((Math.max(...poly.map((q) => q[1])) - y0) / h);
|
|
38
|
+
const G = grid({ nx, ny, h }), density = new Float64Array(G.cells);
|
|
39
|
+
for (let j = 0; j < ny; j++) for (let i = 0; i < nx; i++) {
|
|
40
|
+
let n = 0;
|
|
41
|
+
for (let s = 0; s < 3; s++) for (let t = 0; t < 3; t++) if (inside([x0 + (i + (s + 0.5) / 3) * h, y0 + (j + (t + 0.5) / 3) * h], poly)) n++;
|
|
42
|
+
density[j * nx + i] = n / 9;
|
|
43
|
+
}
|
|
44
|
+
// held: the rim's cut edges (the two radial cuts and the arc under them)
|
|
45
|
+
const at = positions(G).map(([x, y]) => [x + x0, y + y0]), fixed = new Uint8Array(G.dofs);
|
|
46
|
+
const cutA = [[rf * Math.cos(half), rf * Math.sin(half)], [rr * Math.cos(half), rr * Math.sin(half)]], cutB = [[rf * Math.cos(-half), rf * Math.sin(-half)], [rr * Math.cos(-half), rr * Math.sin(-half)]];
|
|
47
|
+
for (let n = 0; n < G.nodes; n++) {
|
|
48
|
+
const q = at[n], r = Math.hypot(...q), near = toSeg(q, ...cutA) < 0.75 * h || toSeg(q, ...cutB) < 0.75 * h || (Math.abs(r - rr) < 0.75 * h && Math.abs(Math.atan2(q[1], q[0])) <= half);
|
|
49
|
+
if (near) fixed[2 * n] = fixed[2 * n + 1] = 1;
|
|
50
|
+
}
|
|
51
|
+
// the load: the mate's push on the lower flank near the tip, along the flank's normal (the line of action), F_t / cos α
|
|
52
|
+
const Ft = torque / (g.pitch / 2), Fn = Ft / Math.cos(a), ra = g.tip / 2;
|
|
53
|
+
const flank = tooth.filter(([x, y]) => y < 0 && Math.hypot(x, y) < ra - 0.2 * m && Math.hypot(x, y) > ra - 0.6 * m);
|
|
54
|
+
const k = Math.floor(flank.length / 2), P = flank[k] ?? tooth[1], Q = flank[Math.min(k + 1, flank.length - 1)] ?? tooth[2];
|
|
55
|
+
const tx = Q[0] - P[0], ty = Q[1] - P[1], tl = Math.hypot(tx, ty) || 1, nIn = [-ty / tl, tx / tl]; // (inward: the tooth is on the left of its outline)
|
|
56
|
+
const load = new Float64Array(G.dofs), touch = [];
|
|
57
|
+
for (let n = 0; n < G.nodes; n++) if (Math.hypot(at[n][0] - P[0], at[n][1] - P[1]) < 0.15 * m) touch.push(n);
|
|
58
|
+
if (!touch.length) throw new Error('toothStress: no node near the load: more cells');
|
|
59
|
+
for (const n of touch) { load[2 * n] = (Fn * nIn[0]) / touch.length; load[2 * n + 1] = (Fn * nIn[1]) / touch.length; }
|
|
60
|
+
const r = analyse({ grid: G, density, material: { E: material.E, nu: material.nu }, thickness: width, fixed, loads: [load], method: 'direct' });
|
|
61
|
+
// the peak on the loaded side (where the root is in tension, as Lewis and the strength mean), away from where the
|
|
62
|
+
// load goes in (a point load's own stress is a property of the model, not the tooth)
|
|
63
|
+
let peak = 0, where = null;
|
|
64
|
+
for (let j = 0; j < ny; j++) for (let i = 0; i < nx; i++) {
|
|
65
|
+
const e = j * nx + i; if (density[e] < 0.5) continue;
|
|
66
|
+
const c = [x0 + (i + 0.5) * h, y0 + (j + 0.5) * h];
|
|
67
|
+
if (c[1] > 0 || Math.hypot(c[0] - P[0], c[1] - P[1]) < 0.6 * m) continue;
|
|
68
|
+
if (r.stress[0][e] > peak) { peak = r.stress[0][e]; where = c; }
|
|
69
|
+
}
|
|
70
|
+
const lewis = Ft / (width * m * lewisFactor(z));
|
|
71
|
+
return { peak, at: where, lewis, h, nx, ny, atRoot: Math.hypot(...where) - rf };
|
|
72
|
+
}
|
package/worm.d.mts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A worm's numbers. module: its axial module (the wheel's transverse module); starts: threads round it (1 to 4);
|
|
3
|
+
* diameter: its pitch diameter (default 10 modules, a stout worm); friction: the coefficient between the flanks
|
|
4
|
+
* (0.25 for printed PLA on PLA, an estimate) for whether it locks and how efficient it is.
|
|
5
|
+
* @param {{ module: number, starts?: number, diameter?: number, pressureAngle?: number, backlash?: number, hand?: 'right' | 'left', friction?: number }} p
|
|
6
|
+
*/
|
|
7
|
+
export function wormModel(p: {
|
|
8
|
+
module: number;
|
|
9
|
+
starts?: number;
|
|
10
|
+
diameter?: number;
|
|
11
|
+
pressureAngle?: number;
|
|
12
|
+
backlash?: number;
|
|
13
|
+
hand?: "right" | "left";
|
|
14
|
+
friction?: number;
|
|
15
|
+
}): {
|
|
16
|
+
kind: string;
|
|
17
|
+
module: any;
|
|
18
|
+
starts: number;
|
|
19
|
+
pitch: any;
|
|
20
|
+
tip: any;
|
|
21
|
+
root: number;
|
|
22
|
+
axialPitch: number;
|
|
23
|
+
lead: number;
|
|
24
|
+
hand: "right" | "left";
|
|
25
|
+
pressureAngle: number;
|
|
26
|
+
backlash: number;
|
|
27
|
+
leadAngle: number;
|
|
28
|
+
friction: number;
|
|
29
|
+
frictionAngle: number;
|
|
30
|
+
locks: boolean;
|
|
31
|
+
efficiency: number;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* A worm: the thread along z, from z = 0 to its length, its axis on z.
|
|
35
|
+
* @param {{ module: number, starts?: number, diameter?: number, length: number, bore?: number, pressureAngle?: number, backlash?: number, hand?: 'right' | 'left' }} p
|
|
36
|
+
*/
|
|
37
|
+
export function worm(p: {
|
|
38
|
+
module: number;
|
|
39
|
+
starts?: number;
|
|
40
|
+
diameter?: number;
|
|
41
|
+
length: number;
|
|
42
|
+
bore?: number;
|
|
43
|
+
pressureAngle?: number;
|
|
44
|
+
backlash?: number;
|
|
45
|
+
hand?: "right" | "left";
|
|
46
|
+
}): jscad.geometries.geom3.Geom3;
|
|
47
|
+
/**
|
|
48
|
+
* The wheel a worm drives: a helical gear at the worm's lead angle, of the worm's hand, its transverse module the
|
|
49
|
+
* worm's axial module. @param {object} wormSpec the worm's parameters @param {{ teeth: number, width: number, bore?: number, shift?: number }} p
|
|
50
|
+
*/
|
|
51
|
+
export function wormWheel(wormSpec: object, p: {
|
|
52
|
+
teeth: number;
|
|
53
|
+
width: number;
|
|
54
|
+
bore?: number;
|
|
55
|
+
shift?: number;
|
|
56
|
+
}): any;
|
|
57
|
+
/**
|
|
58
|
+
* How a worm drives its wheel: the centre distance (axes crossed at 90°), turns of the wheel for one of the worm,
|
|
59
|
+
* whether it locks, and how efficient it is. @param {object} wormSpec @param {{ teeth: number, shift?: number }} wheel
|
|
60
|
+
*/
|
|
61
|
+
export function wormMesh(wormSpec: object, wheel: {
|
|
62
|
+
teeth: number;
|
|
63
|
+
shift?: number;
|
|
64
|
+
}): {
|
|
65
|
+
centre: number;
|
|
66
|
+
ratio: number;
|
|
67
|
+
locks: boolean;
|
|
68
|
+
efficiency: number;
|
|
69
|
+
leadAngle: number;
|
|
70
|
+
findings: any[];
|
|
71
|
+
};
|
|
72
|
+
import jscad from '@jscad/modeling';
|
package/worm.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Worms and their wheels. A worm is a screw whose thread, cut along its axis, is the basic rack's tooth; its wheel is
|
|
2
|
+
// a helical gear at the worm's lead angle, the usual printable wheel (not throated: the two touch at a point, which
|
|
3
|
+
// printed teeth, a little soft, spread). One turn of a worm of s starts moves its wheel s teeth. With a lead angle
|
|
4
|
+
// under the friction angle it locks: the wheel can't turn the worm.
|
|
5
|
+
import jscad from '@jscad/modeling';
|
|
6
|
+
import { rackProfile, helical, gearModel } from './gears.mjs';
|
|
7
|
+
|
|
8
|
+
const { extrudeFromSlices, slice } = jscad.extrusions;
|
|
9
|
+
const { mat4 } = jscad.maths;
|
|
10
|
+
const DEG = Math.PI / 180;
|
|
11
|
+
const fmt = (x, d = 3) => String(+x.toFixed(d));
|
|
12
|
+
const isNum = (x) => typeof x === 'number' && Number.isFinite(x);
|
|
13
|
+
function size(what, k, v) { if (!(isNum(v) && v > 0)) throw new Error(`${what}: ${k} is a size above 0 (got ${JSON.stringify(v)})`); return v; }
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A worm's numbers. module: its axial module (the wheel's transverse module); starts: threads round it (1 to 4);
|
|
17
|
+
* diameter: its pitch diameter (default 10 modules, a stout worm); friction: the coefficient between the flanks
|
|
18
|
+
* (0.25 for printed PLA on PLA, an estimate) for whether it locks and how efficient it is.
|
|
19
|
+
* @param {{ module: number, starts?: number, diameter?: number, pressureAngle?: number, backlash?: number, hand?: 'right' | 'left', friction?: number }} p
|
|
20
|
+
*/
|
|
21
|
+
export function wormModel(p) {
|
|
22
|
+
const what = 'wormModel';
|
|
23
|
+
if (!p || typeof p !== 'object') throw new Error(`${what}: give it { module, starts, diameter }`);
|
|
24
|
+
const m = size(what, 'module', p.module), starts = p.starts ?? 1;
|
|
25
|
+
if (!(Number.isInteger(starts) && starts >= 1 && starts <= 4)) throw new Error(`${what}: starts is a whole number from 1 to 4 (got ${JSON.stringify(p.starts)})`);
|
|
26
|
+
const d = p.diameter === undefined ? 10 * m : size(what, 'diameter', p.diameter);
|
|
27
|
+
if (d < 2 * 1.25 * m + 4 * m) throw new Error(`${what}: a pitch diameter of ${d} mm leaves under two modules of core under the threads (at least ${fmt(6.5 * m)} mm)`);
|
|
28
|
+
const mu = p.friction ?? 0.25, axialPitch = Math.PI * m, lead = starts * axialPitch;
|
|
29
|
+
const gamma = Math.atan(lead / (Math.PI * d)), phi = Math.atan(mu), alpha = (p.pressureAngle ?? 20) * DEG;
|
|
30
|
+
// efficiency driving from the worm, through the normal pressure angle: tan γ (cos αn − μ tan γ) / (cos αn tan γ + μ)
|
|
31
|
+
const an = Math.atan(Math.tan(alpha) * Math.cos(gamma));
|
|
32
|
+
const efficiency = (Math.tan(gamma) * (Math.cos(an) - mu * Math.tan(gamma))) / (Math.cos(an) * Math.tan(gamma) + mu);
|
|
33
|
+
return {
|
|
34
|
+
kind: 'worm', module: m, starts, pitch: d, tip: d + 2 * m, root: d - 2.5 * m, axialPitch, lead, hand: p.hand ?? 'right',
|
|
35
|
+
pressureAngle: alpha / DEG, backlash: p.backlash ?? 0.15, leadAngle: gamma / DEG, friction: mu, frictionAngle: phi / DEG,
|
|
36
|
+
locks: gamma < phi, efficiency,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* A worm: the thread along z, from z = 0 to its length, its axis on z.
|
|
42
|
+
* @param {{ module: number, starts?: number, diameter?: number, length: number, bore?: number, pressureAngle?: number, backlash?: number, hand?: 'right' | 'left' }} p
|
|
43
|
+
*/
|
|
44
|
+
export function worm(p) {
|
|
45
|
+
const w = wormModel(p), length = size('worm', 'length', p.length), m = w.module, r = w.pitch / 2;
|
|
46
|
+
// the thread's axial section: the basic rack's tooth, its pitch line on the pitch radius (heights above it outward)
|
|
47
|
+
const teeth = Math.max(2, w.starts * 2);
|
|
48
|
+
const [loop] = rackProfile({ module: m, teeth, pressureAngle: w.pressureAngle, backlash: w.backlash, height: m }).loops;
|
|
49
|
+
const p0 = w.axialPitch, top = loop.slice(2).reverse().filter(([x]) => x >= p0 && x <= 2 * p0); // one pitch of the top outline, along x
|
|
50
|
+
const heightAt = (u) => { // the rack's height above its pitch line at u along it (one pitch repeating)
|
|
51
|
+
const x = p0 + (((u % p0) + p0) % p0);
|
|
52
|
+
for (let i = 1; i < top.length; i++) if (top[i][0] >= x) { const [a, b] = [top[i - 1], top[i]]; return a[1] + ((b[1] - a[1]) * (x - a[0])) / (b[0] - a[0] || 1); }
|
|
53
|
+
return top.at(-1)[1];
|
|
54
|
+
};
|
|
55
|
+
// the section across the axis at z = 0: a point at angle θ is on the thread's axial section at u = −lead θ / 2π
|
|
56
|
+
const sense = w.hand === 'left' ? -1 : 1, n = 90 * w.starts;
|
|
57
|
+
const section = Array.from({ length: n }, (_, i) => { const t = (2 * Math.PI * i) / n, rho = r + heightAt((-sense * w.lead * t) / (2 * Math.PI)); return [rho * Math.cos(t), rho * Math.sin(t)]; });
|
|
58
|
+
const hole = p.bore ? Array.from({ length: 48 }, (_, i) => { const t = (-2 * Math.PI * i) / 48; return [(p.bore / 2) * Math.cos(t), (p.bore / 2) * Math.sin(t)]; }) : null;
|
|
59
|
+
if (p.bore && !(p.bore < w.root - 2 * m)) throw new Error(`worm: a bore of ${p.bore} mm leaves under a module of wall under the threads`);
|
|
60
|
+
// up the axis the section turns: a turn for each lead, the thread's own helix
|
|
61
|
+
const steps = Math.max(2, Math.ceil((length / w.lead) * 72)), slices = [];
|
|
62
|
+
for (let k = 0; k <= steps; k++) {
|
|
63
|
+
const z = (length * k) / steps, a = (sense * 2 * Math.PI * z) / w.lead, c = Math.cos(a), s = Math.sin(a), at = ([x, y]) => [x * c - y * s, x * s + y * c];
|
|
64
|
+
const sides = [section, ...(hole ? [hole] : [])].flatMap((pts) => pts.map((q, i) => [at(q), at(pts[(i + 1) % pts.length])]));
|
|
65
|
+
slices.push(slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, z]), slice.fromSides(sides)));
|
|
66
|
+
}
|
|
67
|
+
return extrudeFromSlices({ numberOfSlices: slices.length, repair: false, callback: (t, i) => slices[i] }, slices[0]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The wheel a worm drives: a helical gear at the worm's lead angle, of the worm's hand, its transverse module the
|
|
72
|
+
* worm's axial module. @param {object} wormSpec the worm's parameters @param {{ teeth: number, width: number, bore?: number, shift?: number }} p
|
|
73
|
+
*/
|
|
74
|
+
export function wormWheel(wormSpec, p) {
|
|
75
|
+
const w = wormModel(wormSpec);
|
|
76
|
+
return helical({ module: w.module, teeth: p.teeth, width: p.width, bore: p.bore, shift: p.shift, pressureAngle: w.pressureAngle, backlash: w.backlash, helix: w.leadAngle, hand: w.hand, chamfer: p.chamfer });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* How a worm drives its wheel: the centre distance (axes crossed at 90°), turns of the wheel for one of the worm,
|
|
81
|
+
* whether it locks, and how efficient it is. @param {object} wormSpec @param {{ teeth: number, shift?: number }} wheel
|
|
82
|
+
*/
|
|
83
|
+
export function wormMesh(wormSpec, wheel) {
|
|
84
|
+
const w = wormModel(wormSpec), g = gearModel({ module: w.module, teeth: wheel.teeth, shift: wheel.shift ?? 0, pressureAngle: w.pressureAngle, helix: w.leadAngle, hand: w.hand });
|
|
85
|
+
const out = [], f = (level, text, code, values) => out.push({ level, text, code, ...(values ? { values } : {}) });
|
|
86
|
+
const ratio = w.starts / g.teeth;
|
|
87
|
+
f('info', `${g.teeth / w.starts} turns of the worm for one of the wheel; lead angle ${fmt(w.leadAngle, 2)}°`, 'worm.ratio', { ratio });
|
|
88
|
+
if (w.locks) f('pass', `it locks: the lead angle (${fmt(w.leadAngle, 2)}°) is under the friction angle (${fmt(w.frictionAngle, 1)}° at μ ${w.friction}), so the wheel can't turn the worm; ${fmt(w.efficiency * 100, 0)}% efficient driving`, 'worm.locks', { locks: true });
|
|
89
|
+
else f('info', `it doesn't lock: the lead angle (${fmt(w.leadAngle, 2)}°) is over the friction angle (${fmt(w.frictionAngle, 1)}°), so a load on the wheel can turn the worm back; ${fmt(w.efficiency * 100, 0)}% efficient driving`, 'worm.locks', { locks: false });
|
|
90
|
+
if (w.leadAngle > 25) f('warn', `a lead angle of ${fmt(w.leadAngle, 1)}° is steep for a worm: the wheel's teeth lean as much, and print poorly past about 45° at their tips`, 'worm.lead');
|
|
91
|
+
return { centre: (w.pitch + g.pitch) / 2 + (wheel.shift ?? 0) * w.module, ratio, locks: w.locks, efficiency: w.efficiency, leadAngle: w.leadAngle, findings: out };
|
|
92
|
+
}
|