Worm Gear Drive

A right-angle 30:1 worm gear reducer in a half housing: a one-start worm on two ball bearings above a helical bronze wheel, with keys, spacers and shaft seals. The module, the 20 degree pressure angle, the bearing sizes, the key sections and the screw threads are published figures. The foot screws and the filler plug have true helical threads in tapped holes. The turn angle moves the wheel by the tooth ratio, and the kernel measures the volume that the worm thread and the wheel teeth share (zero). The housing, the shafts, the bed and the tooth counts are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, cutAll, cylinder, extrude, faceCenter, fuseAll, getFaces, intersect, line, loft, makeExternalGear, measureVolume, outerWire, polygon, revolve, rotate, sphere, thread, translate, twistExtrude, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Worm gear reducer in a half housing: a one-start worm above a helical bronze wheel, on ball bearings.
// The gear relations, the bearing sizes, the key sections and the screw threads are published figures. The housing,
// the shafts, the bed and the tooth counts are a display model. The wheel shaft is on X, the worm is on Y. Units are millimetres.
interface WormDriveParams {
turn?: number; // degrees of the worm. The wheel turns by turn / teeth.
teeth?: number; // teeth of the wheel, 28 to 40. This is the ratio, and it sets the centre distance.
}
type P2 = [number, number]; // [r, z]
type P3 = [number, number, number];
type Shape = ReturnType<typeof cylinder>;
// Kernel shapes live in WASM memory. Every temporary goes through own(). freeing() runs a build and then frees them all.
const owned: { delete(): void }[] = [];
const own = <T extends { delete(): void }>(s: T): T => {
owned.push(s);
return s;
};
const freeing = <T,>(build: () => T): T => { try { return build(); } finally { owned.splice(0).forEach((s) => s.delete()); } }; // also when the build throws
// ---- published figures
const MODULE = 2; // axial module of the worm = transverse module of the wheel
const PRESSURE = 20; // degrees
const ADDENDUM = 1; // x module
const DEDENDUM = 1.2; // x module
const BEARING_WORM = { d: 10, D: 30, B: 9 }; // 6200
const BEARING_WHEEL = { d: 20, D: 42, B: 12 }; // 6004
const KEY_WHEEL = { width: 8, height: 7, seat: 4 }; // DIN 6885, shaft 22 to 30
const KEY_OUT = { width: 6, height: 6, seat: 3.5 }; // DIN 6885, shaft 17 to 22
const M6 = { major: 6, minor: 4.917, pitch: 1 }; // ISO metric coarse thread, right hand: the foot screws
const M12F = { major: 12, minor: 10.376, pitch: 1.5 }; // ISO metric fine thread M12 x 1.5, right hand: the filler plug
// ---- display model
const WORM = { pitch: 20, turns: 5 }; // pitch diameter, turns of thread
const FACE = 14; // face width of the wheel
const WALL = 6;
const BED = 10; // tapped mounting bed under the foot
const PLAY = 0.08; // radial play between a screw thread and its tapped hole
const X: P3 = [1, 0, 0];
const Y: P3 = [0, 1, 0];
const Z: P3 = [0, 0, 1];
const RAD = Math.PI / 180;
const turned = (s: Shape, deg: number, axis: P3): Shape => own(rotate(s, deg, { axis }) as Shape);
const moved = (s: Shape, v: P3): Shape => own(translate(s, v) as Shape);
const rod = (r: number, from: number, to: number, axis: P3, at: P3 = [0, 0, 0]): Shape =>
own(cylinder(r, to - from, { at: [at[0] + from * axis[0], at[1] + from * axis[1], at[2] + from * axis[2]], axis }));
const lathe = (pts: P2[]): Shape => own(unwrap(revolve(own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z])))), { axis: Z }))) as Shape;
const block = (x: [number, number], y: [number, number], z: [number, number]): Shape =>
own(box(x[1] - x[0], y[1] - y[0], z[1] - z[0], { at: [(x[0] + x[1]) / 2, (y[0] + y[1]) / 2, (z[0] + z[1]) / 2] }));
// One helical thread tooth about +Z, from z = from to z = to, as a smooth loft. Its crest passes the +X side at z = ref.
// tip > core is the thread of a screw on a core of that radius. tip < core is the thread in a bore.
const SECTIONS = 12; // loft sections in each turn
const SLACK = 0.998; // keeps the tooth a hair clear of its core or its bore
const helixTooth = (core: number, tip: number, pitch: number, from: number, to: number, ref: number): Shape => {
const root = tip > core ? core / SLACK : core * SLACK;
const crest = tip > core ? tip : tip / SLACK;
const half = 0.42 * pitch;
const n = Math.max(2, Math.round(((to - from) / pitch) * SECTIONS));
const sections = Array.from({ length: n + 1 }, (_, j) => {
const z = from + ((to - from) * j) / n;
const a = (2 * Math.PI * (z - ref)) / pitch;
const at = (r: number, dz: number): P3 => [r * Math.cos(a), r * Math.sin(a), z + dz];
const pts = [at(root, -half), at(crest, 0), at(root, half)];
return own(unwrap(wire(pts.map((p, i) => own(line(p, pts[(i + 1) % 3]!))))));
});
return unwrap(loft(sections, { ruled: false })) as Shape;
};
// The thread of a screw between two heights, and the mating thread of its tapped hole, half a pitch out of phase.
type Thread = { major: number; minor: number; pitch: number };
const screwTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.minor / 2, m.major / 2, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, 0);
const holeTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.major / 2 + PLAY, m.minor / 2 + PLAY, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, m.pitch / 2);
// A deep groove ball bearing about Z, centred on the origin: two rings and the balls.
function bearing({ d, D, B }: { d: number; D: number; B: number }, count: number): Shape[] {
const rp = (d + D) / 4;
const rb = 0.27 * (D - d) / 2;
const land = 0.45 * rb;
const span = Math.acos(land / (rb + 0.05));
const groove = (side: number): P2[] => Array.from({ length: 13 }, (_, i): P2 => {
const a = -span + (2 * span * i) / 12;
return [rp + side * (rb + 0.05) * Math.cos(a), side * (rb + 0.05) * Math.sin(a)];
});
const ball = own(sphere(rb, { at: [rp, 0, 0] }));
return [
lathe([[d / 2, B / 2], [d / 2, -B / 2], [rp - land, -B / 2], ...groove(-1).reverse(), [rp - land, B / 2]]),
lathe([[D / 2, -B / 2], [D / 2, B / 2], [rp + land, B / 2], ...groove(1).reverse(), [rp + land, -B / 2]]),
...Array.from({ length: count }, (_, i) => turned(ball, (360 * i) / count, Z)),
];
}
function drive({ turn = 0, teeth = 30 }: WormDriveParams = {}) {
const z2 = Math.round(Math.min(Math.max(teeth, 28), 40));
const lead = Math.PI * MODULE; // one start: the lead is the axial pitch
const r1 = WORM.pitch / 2;
const r2 = (MODULE * z2) / 2;
const centres = r1 + r2;
const gamma = Math.atan(lead / (2 * Math.PI * r1)); // lead angle of the worm = helix angle of the wheel
const length = WORM.turns * lead;
const ro = r2 + ADDENDUM * MODULE; // tip radius of the wheel
const chamber = ro + 4;
// ---- worm about Z, thread centred on the origin: a trapezoid thread with 20 degree flanks on a root core
const root = r1 - DEDENDUM * MODULE;
const tip = r1 + ADDENDUM * MODULE;
const flank = Math.tan(PRESSURE * RAD);
const ridge = own(unwrap(thread({ radius: root, pitch: lead, height: length, depth: tip - root, toothHalfWidth: lead / 4 + (r1 - root + 0.3) * flank - 0.08, crest: lead / 4 - (tip - r1) * flank - 0.08, sectionsPerTurn: 16 })));
const bw = BEARING_WORM;
const seat = Math.max(length / 2 + 5, chamber - bw.B - 2); // inner face of a worm bearing
const wormShaft = own(unwrap(cutAll(lathe([
[0, -seat - 40], [4.5, -seat - 40], [4.5, -seat - bw.B - 1], [bw.d / 2, -seat - bw.B - 1], [bw.d / 2, -seat], [7, -seat], [7, -length / 2 - 2], [root + 0.1, -length / 2 - 2],
[root + 0.1, length / 2 + 2], [7, length / 2 + 2], [7, seat], [bw.d / 2, seat], [bw.d / 2, seat + bw.B], [0, seat + bw.B],
]), [block([2.7, 6], [-1.5, 1.5], [-seat - 37, -seat - 21])]))) as Shape;
const wormRaw = own(unwrap(fuseAll([moved(ridge as Shape, [0, 0, -length / 2]), wormShaft]))) as Shape;
const wormKey = block([2.7, 5.7], [-1.5, 1.5], [-seat - 37, -seat - 21]);
const wormSeal = lathe([[4.5, -seat - bw.B - 8], [11, -seat - bw.B - 8], [11, -seat - bw.B - 2], [4.5, -seat - bw.B - 2]]);
const onWorm = (s: Shape, spin = turn): Shape => translate(turned(turned(s, spin, Z), -90, X), [0, 0, centres]) as Shape;
// ---- wheel about Z: an involute gear, twisted by the helix angle, with a hub, web recesses and a keyway
const b = FACE;
const twist = ((b * Math.tan(gamma)) / r2) / RAD;
const flat = own(unwrap(makeExternalGear({ teeth: z2, moduleSize: MODULE, thickness: 1, flankThinning: 0.12, samples: 5 })).solid);
const base = getFaces(flat).find((f) => Math.abs(faceCenter(f)[2]) < 1e-6);
if (!base) throw new Error('gear face not found');
const helical = own(unwrap(twistExtrude(outerWire(base), twist, [0, 0, 0], [0, 0, b]))) as Shape;
const kw = KEY_WHEEL;
const wheelRaw = own(unwrap(cutAll(moved(helical, [0, 0, -b / 2]), [
rod(12, -14, 14, Z), block([0, 12 + kw.height - kw.seat + 0.3], [-kw.width / 2, kw.width / 2], [-14, 14]),
lathe([[19, 4], [r2 - 6, 4], [r2 - 6, 9], [19, 9]]), lathe([[19, -9], [r2 - 6, -9], [r2 - 6, -4], [19, -4]]),
]))) as Shape;
const spacer = lathe([[12, b / 2], [15, b / 2], [15, 13], [12, 13]]); // between the wheel and a bearing
// The wheel angle that puts a tooth space on the worm thread, at the top of the wheel.
const mesh = 180 - twist / 2 - 180 / z2 - (360 / z2) * (0.25 - WORM.turns / 2) + turn / z2;
const onWheel = (s: Shape, spin = mesh): Shape => rotate(turned(s, spin, Z), 90, { axis: Y }) as Shape;
// ---- wheel shaft about Z: seat, two journals, output end with a keyway
const bo = BEARING_WHEEL;
const ko = KEY_OUT;
const shaftRaw = own(unwrap(cutAll(lathe([[0, -27], [10, -27], [10, -13], [12, -13], [12, 13], [10, 13], [10, 34], [9, 34], [9, 67], [8, 68], [0, 68]]), [
block([12 - kw.seat, 13], [-kw.width / 2, kw.width / 2], [-7, 7]), block([9 - ko.seat, 10], [-ko.width / 2, ko.width / 2], [38, 63]),
]))) as Shape;
const wheelKey = block([12 - kw.seat, 12 - kw.seat + kw.height], [-kw.width / 2, kw.width / 2], [-7, 7]);
const outKey = block([9 - ko.seat, 9 - ko.seat + ko.height], [-ko.width / 2, ko.width / 2], [38, 63]);
const outSeal = lathe([[10, 27], [17, 27], [17, 33], [10, 33]]);
// ---- half housing: the part behind the middle plane of the wheel
const back = -13 - bo.B - WALL; // outside of the back wall
const floor = -chamber - WALL;
const side = seat + bw.B + 8; // outside of an end wall of the worm
const foot: Shape[] = [-1, 1].map((s) => rod(3.3, floor - 9, floor + 1, Z, [back / 2, s * (side + 8), 0]));
const housing = unwrap(cutAll(own(unwrap(fuseAll([
block([back, 0], [-side, side], [floor, centres]), rod(22, -side, side, Y, [0, 0, centres]), rod(28, back - 5, back + 1, X),
block([back - 4, 0], [-side - 16, side + 16], [floor - 7, floor + 0.5]), rod(9, centres + 15, centres + 23, Z, [-10, 0, 0]),
]))) as Shape, [
rod(chamber, -12.5, 2, X), rod(bo.D / 2, -13 - bo.B, 2, X), rod(11, back + 2.5, 2, X),
rod(14.5, -seat, seat, Y, [0, 0, centres]), rod(bw.D / 2, -seat - bw.B, seat + bw.B, Y, [0, 0, centres]),
rod(6, -side - 1, 0, Y, [0, 0, centres]), rod(11, -side - 1, -seat - bw.B - 2, Y, [0, 0, centres]),
block([0, 40], [-200, 200], [-200, 200]), ...foot, rod(M12F.major / 2 + PLAY, centres + 11, centres + 24, Z, [-10, 0, 0]),
])) as Shape;
const hex = (af: number, z0: number, z1: number): Shape => own(unwrap(extrude(own(unwrap(polygon(Array.from({ length: 6 }, (_, i): P3 => [(af / Math.sqrt(3)) * Math.cos(i * 60 * RAD), (af / Math.sqrt(3)) * Math.sin(i * 60 * RAD), z0])))), z1 - z0))) as Shape;
// Foot screws: M6 x 16 hex screws through the foot into the tapped bed. Each thread is one helical tooth.
const feet: P3[] = [-1, 1].map((s): P3 => [back / 2, s * (side + 8), 0]);
const boltEnd = floor + 0.5 - 16;
const boltRaw = own(unwrap(fuseAll([hex(10, floor + 0.5, floor + 4.5), rod(M6.minor / 2, boltEnd, floor + 1, Z)]))) as Shape;
const boltTooth = own(screwTooth(M6, boltEnd, floor + 0.5));
const bedTooth = own(holeTooth(M6, floor - 7 - BED, floor - 7));
const bed = unwrap(cutAll(block([back - 10, 0], [-side - 22, side + 22], [floor - 7 - BED, floor - 7]), feet.map((at) => rod(M6.major / 2 + PLAY, floor - 8 - BED, floor - 6, Z, at)))) as Shape;
// Filler plug: M12 x 1.5 into the tapped boss, 10 mm of thread.
const plugRaw = own(unwrap(fuseAll([hex(14, centres + 24, centres + 29), rod(9, centres + 23, centres + 24.2, Z), rod(M12F.minor / 2, centres + 13, centres + 23.5, Z)]))) as Shape;
const plugTooth = own(screwTooth(M12F, centres + 13, centres + 23));
const bossTooth = own(holeTooth(M12F, centres + 14, centres + 23));
const wormBearing = bearing(bw, 8);
const wheelBearing = bearing(bo, 9);
const onAxis = (parts: Shape[], place: (s: Shape, spin?: number) => Shape, offset: number): Shape[] => parts.map((s) => place(moved(s, [0, 0, offset]), 0));
const worm = onWorm(wormRaw);
const wheel = onWheel(wheelRaw);
const clash = unwrap(measureVolume(own(unwrap(intersect(worm, wheel)))));
return {
housing, worm, wheel, shaft: onWheel(shaftRaw), clash,
keys: [onWorm(wormKey), onWheel(wheelKey), onWheel(outKey)], spacers: [onWheel(spacer), onWheel(turned(spacer, 180, X))],
seals: [onWorm(wormSeal, 0), onWheel(outSeal, 0)],
bearings: [...onAxis(wormBearing, onWorm, seat + bw.B / 2), ...onAxis(wormBearing, onWorm, -seat - bw.B / 2), ...onAxis(wheelBearing, onWheel, 13 + bo.B / 2), ...onAxis(wheelBearing, onWheel, -13 - bo.B / 2)],
bolts: feet.flatMap((at) => [translate(boltRaw, at) as Shape, translate(boltTooth, at) as Shape]),
bed: [bed, ...feet.map((at) => translate(bedTooth, at) as Shape)],
plug: [translate(plugRaw, [-10, 0, 0]) as Shape, translate(plugTooth, [-10, 0, 0]) as Shape],
bossTooth: translate(bossTooth, [-10, 0, 0]) as Shape,
ratio: z2, centres, gamma: gamma / RAD, turn, out: turn / z2,
};
}
const part = freeing(() => drive());
console.log('Ratio ' + part.ratio + ':1. Worm at ' + part.turn + ' deg, wheel at ' + part.out.toFixed(2) + ' deg. Centre distance ' + part.centres + ' mm, lead angle ' + part.gamma.toFixed(2) + ' deg.');
console.log('Volume that the worm thread and the wheel teeth share, from the kernel: ' + part.clash.toFixed(3) + ' mm3.');
export default [
color(part.housing, '#c3c9d1'),
color(part.bossTooth, '#c3c9d1'),
color(part.worm, '#f5f2ea'),
color(part.wheel, '#d3a956'),
color(part.shaft, '#12b5b0'),
...part.keys.map((s) => color(s, '#48515c')),
...part.spacers.map((s) => color(s, '#8f98a3')),
...part.seals.map((s) => color(s, '#ff5a1f')),
...part.bearings.map((s) => color(s, '#8f98a3')),
...part.bolts.map((s) => color(s, '#48515c')),
...part.bed.map((s) => color(s, '#8f98a3')),
...part.plug.map((s) => color(s, '#d3a956')),
];Functions used
box cutAll cylinder extrude faceCenter fuseAll getFaces intersect line loft makeExternalGear measureVolume outerWire polygon revolve rotate sphere thread translate twistExtrude unwrap wire color