@rulecad/gears 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog: @rulecad/gears
2
+
3
+ What changed in each release, for someone upgrading a workspace. A **printed size** is a dimension of a part you
4
+ print (a gear's tip diameter, a tooth's thickness). Each release says whether any printed size moved, and why.
5
+ Releases before this file was started are described in their pull requests on GitHub.
6
+
7
+ ## 0.3.3: no import loops (#278)
8
+
9
+ ### Fixed
10
+
11
+ - Loaders without cycle support, such as the JSCAD web app's, now load this package. Its modules imported each other
12
+ in a loop (issue #278): Node links such a loop and runs it, but a loader that caches a module only once it has run
13
+ loads it again and again until the stack runs out (`RangeError: Maximum call stack size exceeded / failed loading
14
+ module ...`).
15
+ - The code the other modules share moved from `gears.mjs` to a new `core.mjs`, which `planetary.mjs`, `contact.mjs`,
16
+ `tooth.mjs`, `worm.mjs` and `diagram.mjs` import. `gears.mjs` now only re-exports. Every export keeps its name and
17
+ behaviour, and no printed size moved.
package/contact.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  // real fillets, rounds and centre distance); how far the forward meeting is from where the ratio puts it is the
4
4
  // transmission error; outlines that cross where the ratio puts them interfere. Plain 2D geometry: the outlines'
5
5
  // edges near the pitch point, tested for crossing.
6
- import { spurProfile, internalProfile, rackProfile, gearModel, internalModel, rackModel, mesh, phase, rackPhase } from './gears.mjs';
6
+ import { spurProfile, internalProfile, rackProfile, gearModel, internalModel, rackModel, mesh, phase, rackPhase } from './core.mjs';
7
7
 
8
8
  const DEG = Math.PI / 180;
9
9
  const fmt = (x, d = 3) => String(+x.toFixed(d));
package/core.d.mts ADDED
@@ -0,0 +1,419 @@
1
+ /**
2
+ * A spur gear's numbers: its circles, tooth thickness, and the limits it was checked against. Refuses a gear whose teeth
3
+ * would be undercut (fewer than about 17 at 20°: give it a profile shift) or come to a point.
4
+ * @param {GearSpec} p
5
+ * @returns {GearModel}
6
+ */
7
+ export function gearModel(p: GearSpec): GearModel;
8
+ /**
9
+ * An internal (ring) gear's numbers: the teeth point inwards, tip circle inside the pitch circle. Its spaces are shaped
10
+ * as an outer gear's teeth would be. `rim` is the ring's outer diameter (default: the root diameter and six modules).
11
+ * @param {GearSpec & { rim?: number }} p
12
+ * @returns {GearModel & { rim: number, space: number }}
13
+ */
14
+ export function internalModel(p: GearSpec & {
15
+ rim?: number;
16
+ }): GearModel & {
17
+ rim: number;
18
+ space: number;
19
+ };
20
+ /**
21
+ * A rack's numbers: a gear of infinite radius, its teeth straight-flanked at the pressure angle. Its pitch line is y = 0,
22
+ * teeth up +y, the first space centred at x = 0. `height` is how much bar there is under the roots (default 3 modules).
23
+ * @param {GearSpec & { height?: number }} p
24
+ */
25
+ export function rackModel(p: GearSpec & {
26
+ height?: number;
27
+ }): {
28
+ kind: string;
29
+ module: any;
30
+ teeth: any;
31
+ pressureAngle: any;
32
+ shift: number;
33
+ backlash: any;
34
+ height: any;
35
+ thickness: number;
36
+ helix: any;
37
+ hand: any;
38
+ herringbone: boolean;
39
+ thrust: number;
40
+ length: number;
41
+ tipLine: number;
42
+ rootLine: number;
43
+ circularPitch: number;
44
+ basePitch: number;
45
+ topLand: number;
46
+ rootThickness: number;
47
+ rack: {
48
+ pressureAngle: any;
49
+ addendum: any;
50
+ dedendum: any;
51
+ rootFillet: any;
52
+ tipRound: any;
53
+ };
54
+ };
55
+ /**
56
+ * A spur gear's outline in 2D, as loops of [x, y] points (the first the outside, counter-clockwise; then holes,
57
+ * clockwise), and the fillet and round it was drawn with (smaller than asked where the asked one didn't fit).
58
+ * @param {GearSpec & { bore?: number, flat?: number }} p
59
+ * @param {number} [grow] outwards along the outline's normal, mm (negative: inwards)
60
+ */
61
+ export function spurProfile(p: GearSpec & {
62
+ bore?: number;
63
+ flat?: number;
64
+ }, grow?: number): {
65
+ loops: number[][][];
66
+ fillet: any;
67
+ round: any;
68
+ model: GearModel;
69
+ };
70
+ /** An internal gear's outline: the rim (counter-clockwise), then the teeth's inner outline (clockwise). */
71
+ export function internalProfile(p: any, grow?: number): {
72
+ loops: any[][];
73
+ fillet: any;
74
+ round: any;
75
+ model: GearModel & {
76
+ rim: number;
77
+ space: number;
78
+ };
79
+ };
80
+ /** A rack's outline: one loop, counter-clockwise, its pitch line on y = 0, teeth up +y from x = 0. */
81
+ export function rackProfile(p: any, grow?: number): {
82
+ loops: any[][];
83
+ fillet: any;
84
+ round: any;
85
+ model: {
86
+ kind: string;
87
+ module: any;
88
+ teeth: any;
89
+ pressureAngle: any;
90
+ shift: number;
91
+ backlash: any;
92
+ height: any;
93
+ thickness: number;
94
+ helix: any;
95
+ hand: any;
96
+ herringbone: boolean;
97
+ thrust: number;
98
+ length: number;
99
+ tipLine: number;
100
+ rootLine: number;
101
+ circularPitch: number;
102
+ basePitch: number;
103
+ topLand: number;
104
+ rootThickness: number;
105
+ rack: {
106
+ pressureAngle: any;
107
+ addendum: any;
108
+ dedendum: any;
109
+ rootFillet: any;
110
+ tipRound: any;
111
+ };
112
+ };
113
+ };
114
+ /** @typedef {{ width: number, chamfer?: number | [number, number], bore?: number, flat?: number }} Solid width up z; chamfer at the bed face (and the top); bore and flat for a shaft */
115
+ /**
116
+ * A spur gear: the profile extruded up z, its first tooth on +x, the bed face chamfered.
117
+ * @param {GearSpec & Solid} p
118
+ * @returns {object} a JSCAD geom3
119
+ */
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;
130
+ /** An internal (ring) gear, its rim round it. @param {GearSpec & Solid & { rim?: number }} p */
131
+ export function internal(p: GearSpec & Solid & {
132
+ rim?: number;
133
+ }): jscad.geometries.geom3.Geom3;
134
+ /** A rack along x, its teeth up +y, its width up z. @param {GearSpec & Solid & { height?: number }} p */
135
+ export function rack(p: GearSpec & Solid & {
136
+ height?: number;
137
+ }): jscad.geometries.geom3.Geom3;
138
+ /**
139
+ * How two gears mesh: the centre distance they need (with their profile shifts), the ratio (turns of b for one of a,
140
+ * negative when they turn opposite ways; for a rack, mm for one turn of the pinion), the contact ratio (how many teeth
141
+ * share the load on average: under 1 the drive jumps, under 1.2 it is rough), and findings. Give `centre` (mm) to have
142
+ * a centre distance checked: closer than needed jams the teeth, further adds backlash.
143
+ * @param {GearModel} a @param {GearModel} b @param {{ centre?: number }} [o]
144
+ */
145
+ export function mesh(a: GearModel, b: GearModel, { centre, width }?: {
146
+ centre?: number;
147
+ }): any;
148
+ /**
149
+ * The phase that puts a tooth in a gap: b's angle is ratio × a's angle + phase. Both gears have their first tooth at
150
+ * their own angle 0; `angle` is the direction from a's centre to b's, in degrees, in the frame both angles are measured in.
151
+ * For a pinion in a ring, a is the pinion. Returns degrees, in [0, 360 / b's teeth).
152
+ * @param {GearModel} a @param {GearModel} b @param {number} [angle]
153
+ */
154
+ export function phase(a: GearModel, b: GearModel, angle?: number): number;
155
+ /**
156
+ * Where a rack must stand so the pinion's teeth fall in its spaces: the rack's travel is (π × pitch diameter / 360) ×
157
+ * the pinion's angle + this, in mm. The rack lies along x with its pitch line on y = 0 and its first space at x = 0;
158
+ * the pinion's centre is at x = `at`, above the rack, its first tooth pointing along +x at angle 0.
159
+ * @param {GearModel} pinion @param {number} [at] @returns {number} mm, in [0, the circular pitch)
160
+ */
161
+ export function rackPhase(pinion: GearModel, at?: number): number;
162
+ /**
163
+ * How a gear prints on a printer ({ line, layer, nozzle?, wall_min? }): the module against the nozzle, lines across a
164
+ * tooth at its root and its tip, and the width in layers. Findings in the kit's shape, each placed on the first tooth.
165
+ * @param {GearModel} g @param {{ line: number, layer: number, nozzle?: number, wall_min?: number }} printer @param {number} [width]
166
+ */
167
+ export function printable(g: GearModel, printer: {
168
+ line: number;
169
+ layer: number;
170
+ nozzle?: number;
171
+ wall_min?: number;
172
+ }, width?: number): any[];
173
+ /**
174
+ * How much of the power a stage passes on: DEFAULTS.efficiency per mesh a tooth force goes through. A planetary's
175
+ * goes through two (sun to planet, planet to ring); a worm's is its own, from its lead angle and friction.
176
+ * @param {'spur' | 'helical' | 'herringbone' | 'rack' | 'internal' | 'bevel' | 'planetary' | 'worm'} kind
177
+ * @param {{ efficiency?: number, worm?: { efficiency: number } }} [o] efficiency: your measured figure per mesh
178
+ * @returns {number} from 0 to 1
179
+ */
180
+ export function stageEfficiency(kind: "spur" | "helical" | "herringbone" | "rack" | "internal" | "bevel" | "planetary" | "worm", o?: {
181
+ efficiency?: number;
182
+ worm?: {
183
+ efficiency: number;
184
+ };
185
+ }): number;
186
+ /** The Lewis form factor Y for z teeth (20° full depth); Infinity for a rack. @param {number} z */
187
+ export function lewisFactor(z: number): number;
188
+ /**
189
+ * How strong a gear's teeth are by the Lewis equation: the bending stress at the root of a tooth carrying the whole
190
+ * load at its tip, σ = F_t / (b m Y), against the material's strength. Give a torque (N·mm) for the stress and safety
191
+ * factor at it; give a safety factor for the torque the gear carries at it. Helical teeth are read in their normal
192
+ * section (m cos β, z / cos³β teeth). A speed (rpm) adds Barth's velocity factor, (3.05 + V) / 3.05 for a cut (here a
193
+ * printed) profile. A first number: the root fillet and a tooth's neighbours help, a printed tooth's layers and
194
+ * voids hurt. Where it matters, measure it, or analyse the tooth (fea).
195
+ * @param {GearModel} g
196
+ * @param {{ width: number, material: { strength: number, name?: string }, torque?: number, safety?: number, speed?: number }} o
197
+ */
198
+ export function strength(g: GearModel, o?: {
199
+ width: number;
200
+ material: {
201
+ strength: number;
202
+ name?: string;
203
+ };
204
+ torque?: number;
205
+ safety?: number;
206
+ speed?: number;
207
+ }): {
208
+ Y: number;
209
+ velocity: number;
210
+ force: number;
211
+ torque: number;
212
+ findings: any[];
213
+ };
214
+ /**
215
+ * A straight bevel gear's numbers, for a mate of `mate` teeth with the shafts at `shaftAngle` (90° by default): the
216
+ * pitch cone angle δ (tan δ = sin Σ / (z₂/z₁ + cos Σ)), the cone distance R (to the apex along the pitch cone), the
217
+ * virtual teeth z / cos δ of its back cone (Tredgold), and the face width's limit R / 3. Module and diameters at the
218
+ * back (large) end.
219
+ * @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, pressureAngle?: number, backlash?: number }} p
220
+ */
221
+ export function bevelModel(p: {
222
+ module: number;
223
+ teeth: number;
224
+ mate: number;
225
+ shaftAngle?: number;
226
+ width?: number;
227
+ pressureAngle?: number;
228
+ backlash?: number;
229
+ }): {
230
+ kind: string;
231
+ mate: any;
232
+ shaftAngle: number;
233
+ pitchAngle: number;
234
+ coneDistance: number;
235
+ virtualTeeth: number;
236
+ width: any;
237
+ height: number;
238
+ smallEnd: number;
239
+ module: number;
240
+ teeth: number;
241
+ /**
242
+ * degrees
243
+ */
244
+ pressureAngle: number;
245
+ /**
246
+ * times the module
247
+ */
248
+ shift: number;
249
+ /**
250
+ * mm, this gear's share is half
251
+ */
252
+ backlash: number;
253
+ /**
254
+ * pitch diameter, module × teeth
255
+ */
256
+ pitch: number;
257
+ /**
258
+ * base circle diameter
259
+ */
260
+ base: number;
261
+ /**
262
+ * tip diameter
263
+ */
264
+ tip: number;
265
+ /**
266
+ * root diameter
267
+ */
268
+ root: number;
269
+ /**
270
+ * tooth thickness on the pitch circle (an arc, mm), less half the backlash
271
+ */
272
+ thickness: number;
273
+ /**
274
+ * π × module
275
+ */
276
+ circularPitch: number;
277
+ /**
278
+ * π × module × cos(pressure angle)
279
+ */
280
+ basePitch: number;
281
+ /**
282
+ * the tooth's width across its tip (mm)
283
+ */
284
+ topLand: number;
285
+ /**
286
+ * the tooth's width where it meets the root (mm)
287
+ */
288
+ rootThickness: number;
289
+ /**
290
+ * the basic rack it was drawn from
291
+ */
292
+ rack: {
293
+ pressureAngle: number;
294
+ addendum: number;
295
+ dedendum: number;
296
+ rootFillet: number;
297
+ tipRound: number;
298
+ };
299
+ };
300
+ /**
301
+ * 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
302
+ * profile of its back end scaled toward the apex up the face width, so every tooth runs straight to the apex and the
303
+ * pitch surface is the cone. (A printable approximation to the octoidal profile: close for teeth of 12 or more.)
304
+ * @param {{ module: number, teeth: number, mate: number, shaftAngle?: number, width?: number, bore?: number, chamfer?: number }} p
305
+ */
306
+ export function bevel(p: {
307
+ module: number;
308
+ teeth: number;
309
+ mate: number;
310
+ shaftAngle?: number;
311
+ width?: number;
312
+ bore?: number;
313
+ chamfer?: number;
314
+ }): jscad.geometries.geom3.Geom3;
315
+ /**
316
+ * How two bevel gears mesh: turns of b for one of a, the cone angles (they add to the shaft angle), and the contact
317
+ * ratio of their back cones' equivalent spur gears (Tredgold). @param {object} a @param {object} b the gears' parameters
318
+ */
319
+ export function bevelMesh(a: object, b: object): {
320
+ ratio: number;
321
+ pitchAngles: number[];
322
+ coneDistance: number;
323
+ contact: any;
324
+ findings: any[];
325
+ };
326
+ /**
327
+ * The defaults, each with the rule it comes from. Coefficients are times the module.
328
+ * @type {Record<string, { value: number, unit: string, rule: string, kind: string }>}
329
+ */
330
+ export const DEFAULTS: Record<string, {
331
+ value: number;
332
+ unit: string;
333
+ rule: string;
334
+ kind: string;
335
+ }>;
336
+ /**
337
+ * width up z; chamfer at the bed face (and the top); bore and flat for a shaft
338
+ */
339
+ export type Solid = {
340
+ width: number;
341
+ chamfer?: number | [number, number];
342
+ bore?: number;
343
+ flat?: number;
344
+ };
345
+ export type GearSpec = {
346
+ module: number;
347
+ teeth: number;
348
+ pressureAngle?: number;
349
+ shift?: number;
350
+ backlash?: number;
351
+ addendum?: number;
352
+ dedendum?: number;
353
+ rootFillet?: number;
354
+ tipRound?: number;
355
+ };
356
+ export type GearModel = {
357
+ kind: "external" | "internal";
358
+ module: number;
359
+ teeth: number;
360
+ /**
361
+ * degrees
362
+ */
363
+ pressureAngle: number;
364
+ /**
365
+ * times the module
366
+ */
367
+ shift: number;
368
+ /**
369
+ * mm, this gear's share is half
370
+ */
371
+ backlash: number;
372
+ /**
373
+ * pitch diameter, module × teeth
374
+ */
375
+ pitch: number;
376
+ /**
377
+ * base circle diameter
378
+ */
379
+ base: number;
380
+ /**
381
+ * tip diameter
382
+ */
383
+ tip: number;
384
+ /**
385
+ * root diameter
386
+ */
387
+ root: number;
388
+ /**
389
+ * tooth thickness on the pitch circle (an arc, mm), less half the backlash
390
+ */
391
+ thickness: number;
392
+ /**
393
+ * π × module
394
+ */
395
+ circularPitch: number;
396
+ /**
397
+ * π × module × cos(pressure angle)
398
+ */
399
+ basePitch: number;
400
+ /**
401
+ * the tooth's width across its tip (mm)
402
+ */
403
+ topLand: number;
404
+ /**
405
+ * the tooth's width where it meets the root (mm)
406
+ */
407
+ rootThickness: number;
408
+ /**
409
+ * the basic rack it was drawn from
410
+ */
411
+ rack: {
412
+ pressureAngle: number;
413
+ addendum: number;
414
+ dedendum: number;
415
+ rootFillet: number;
416
+ tipRound: number;
417
+ };
418
+ };
419
+ import jscad from '@jscad/modeling';