@rulecad/gears 0.2.0 → 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 +48 -1
- package/contact.d.mts +31 -0
- package/contact.mjs +79 -0
- package/gears.d.mts +115 -0
- package/gears.mjs +84 -4
- package/package.json +11 -2
- 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
|
@@ -79,7 +79,8 @@ What every gear takes:
|
|
|
79
79
|
1.2 it is rough.
|
|
80
80
|
- **`backlash`**: the play, with the centre you gave.
|
|
81
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
|
|
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
|
|
83
84
|
`mesh.pressure` (gears that can't mesh), `mesh.interference` (a ring too near its pinion's size), `mesh.helix` (helical
|
|
84
85
|
gears that cross: outer gears that mesh are of opposite hands; a pinion and its ring or rack, of the same hand).
|
|
85
86
|
|
|
@@ -102,6 +103,39 @@ planet's place round the carrier and the turn that puts it in phase with the sun
|
|
|
102
103
|
gives the ratio exactly, the nearest is returned and `planetary.ratio` says how far off it is (a fail past 5%).
|
|
103
104
|
`planetaryRatio({ sun, ring }, { held, input, output })` is the ratio of any teeth, any way round.
|
|
104
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
|
+
|
|
105
139
|
## How it prints
|
|
106
140
|
|
|
107
141
|
`printable(model, printer, width)` reads the gear against the printer (`{ line, layer, nozzle, wall_min }`, as in
|
|
@@ -136,6 +170,14 @@ strength(gearModel({ module: 1, teeth: 18 }), { width: 6, material: { strength:
|
|
|
136
170
|
It is a first number. A printed tooth is weaker than a moulded one where its layers and voids are, and stronger than
|
|
137
171
|
Lewis says where the root fillet and its neighbours share the load. Where it matters, print one and load it.
|
|
138
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
|
+
|
|
139
181
|
## What isn't refused, and what is
|
|
140
182
|
|
|
141
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
|
|
@@ -166,6 +208,11 @@ a point.
|
|
|
166
208
|
| Planetary assembly | R = S + 2P; (S + R) / n whole; 2a sin(π / n) > d_a,planet | KHK, planetary gears |
|
|
167
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 |
|
|
168
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 |
|
|
169
216
|
|
|
170
217
|
## Words used
|
|
171
218
|
|
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
|
@@ -198,6 +198,118 @@ export function strength(g: GearModel, o?: {
|
|
|
198
198
|
torque: number;
|
|
199
199
|
findings: any[];
|
|
200
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
|
+
};
|
|
201
313
|
/**
|
|
202
314
|
* The defaults, each with the rule it comes from. Coefficients are times the module.
|
|
203
315
|
* @type {Record<string, { value: number, unit: string, rule: string, kind: string }>}
|
|
@@ -208,6 +320,8 @@ export const DEFAULTS: Record<string, {
|
|
|
208
320
|
rule: string;
|
|
209
321
|
kind: string;
|
|
210
322
|
}>;
|
|
323
|
+
export { contact } from "./contact.mjs";
|
|
324
|
+
export { toothStress } from "./tooth.mjs";
|
|
211
325
|
/**
|
|
212
326
|
* width up z; chamfer at the bed face (and the top); bore and flat for a shaft
|
|
213
327
|
*/
|
|
@@ -293,3 +407,4 @@ export type GearModel = {
|
|
|
293
407
|
};
|
|
294
408
|
import jscad from '@jscad/modeling';
|
|
295
409
|
export { planetary, planetaryRatio } from "./planetary.mjs";
|
|
410
|
+
export { wormModel, worm, wormWheel, wormMesh } from "./worm.mjs";
|
package/gears.mjs
CHANGED
|
@@ -253,6 +253,7 @@ function loop({ teeth: z, thickness: s, r, rb, ra, rf, fillet, round, grow = 0 }
|
|
|
253
253
|
flankT: (rho) => -hAt(rho), point: (t, rho) => [rho * Math.cos(t), rho * Math.sin(t)],
|
|
254
254
|
});
|
|
255
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 };
|
|
256
257
|
const out = [];
|
|
257
258
|
for (let k = 0; k < z; k++) {
|
|
258
259
|
const c = Math.cos((TAU * k) / z), sn = Math.sin((TAU * k) / z);
|
|
@@ -324,7 +325,7 @@ export function rackProfile(p, grow = 0) {
|
|
|
324
325
|
|
|
325
326
|
// A solid from loops at heights: each slice is the loops at a height, grown (a chamfer: drawn smaller there) and turned
|
|
326
327
|
// (a helix), all with the same points, so the walls join point to point. Caps are triangulated with their holes.
|
|
327
|
-
function loft(profile, width, { chamfer, twist, slide }) {
|
|
328
|
+
function loft(profile, width, { chamfer, twist, slide, scale }) {
|
|
328
329
|
const [bottom, top] = Array.isArray(chamfer) ? chamfer : [chamfer, 0];
|
|
329
330
|
if (bottom + top >= width) throw new Error(`the chamfers (${bottom} and ${top} mm) are as tall as the gear (${width} mm)`);
|
|
330
331
|
// heights: the chamfers' ends, and for a twist enough between that no slice turns more than a degree or so
|
|
@@ -335,10 +336,11 @@ function loft(profile, width, { chamfer, twist, slide }) {
|
|
|
335
336
|
zs.push(width / 2); // (a herringbone's apex)
|
|
336
337
|
}
|
|
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)
|
|
338
340
|
const heights = [...new Set(zs.map((z) => +z.toFixed(9)))].sort((x, y) => x - y);
|
|
339
341
|
const slices = heights.map((z) => {
|
|
340
342
|
const grow = z < bottom ? -(bottom - z) : z > width - top ? -(z - (width - top)) : 0;
|
|
341
|
-
const loops = profile(grow), turn = twist ? twist(z) : 0, c = Math.cos(turn), s = Math.sin(turn), dx = slide ? slide(z) : 0;
|
|
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;
|
|
342
344
|
const at = (p) => [p[0] * c - p[1] * s + dx, p[0] * s + p[1] * c];
|
|
343
345
|
const sides = loops.flatMap((pts) => pts.map((p, i) => [at(p), at(pts[(i + 1) % pts.length])]));
|
|
344
346
|
return slice.transform(mat4.fromTranslation(mat4.create(), [0, 0, z]), slice.fromSides(sides));
|
|
@@ -473,9 +475,13 @@ export function mesh(a, b, { centre, width } = {}) {
|
|
|
473
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
|
|
474
476
|
const added = 2 * off * Math.tan(aw);
|
|
475
477
|
backlash += added;
|
|
476
|
-
|
|
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 });
|
|
477
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 });
|
|
478
|
-
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 });
|
|
479
485
|
}
|
|
480
486
|
const thrust = a.herringbone || !ha ? 0 : Math.tan(ha * DEG);
|
|
481
487
|
return { kind: b.kind, centre: need, ratio, contact, overlap, thrust, pressureAngle: aw / DEG, backlash, text: sense, findings: out };
|
|
@@ -551,6 +557,12 @@ export function printable(g, printer, width) {
|
|
|
551
557
|
|
|
552
558
|
// Planetary gearboxes: the teeth for a ratio, laid out in phase
|
|
553
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';
|
|
554
566
|
|
|
555
567
|
// ---------- strength ----------
|
|
556
568
|
|
|
@@ -600,3 +612,71 @@ export function strength(g, o = {}) {
|
|
|
600
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 });
|
|
601
613
|
return result;
|
|
602
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": {
|
|
@@ -16,9 +16,15 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"gears.mjs",
|
|
18
18
|
"planetary.mjs",
|
|
19
|
+
"contact.mjs",
|
|
20
|
+
"tooth.mjs",
|
|
21
|
+
"worm.mjs",
|
|
19
22
|
"diagram.mjs",
|
|
20
23
|
"gears.d.mts",
|
|
21
24
|
"planetary.d.mts",
|
|
25
|
+
"contact.d.mts",
|
|
26
|
+
"tooth.d.mts",
|
|
27
|
+
"worm.d.mts",
|
|
22
28
|
"diagram.d.mts",
|
|
23
29
|
"README.md",
|
|
24
30
|
"LICENSE"
|
|
@@ -51,5 +57,8 @@
|
|
|
51
57
|
"peerDependencies": {
|
|
52
58
|
"@jscad/modeling": "^2.12.0"
|
|
53
59
|
},
|
|
54
|
-
"types": "./gears.d.mts"
|
|
60
|
+
"types": "./gears.d.mts",
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"@rulecad/fea": "^0.2.9"
|
|
63
|
+
}
|
|
55
64
|
}
|
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
|
+
}
|