GT2 Timing Pulley and Belt

A 20-tooth GT2 pulley on a closed 80-tooth belt that drives a 40-tooth pulley. The 2 mm pitch, the pitch-line offset and the three-arc groove form are published figures. The kernel measures the pitch line, which must equal the belt length. The flanges, the hubs, the set screws and the shafts are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { compound, cut, cutAll, cylinder, extrude, face, line, loft, measureLength, polygon, revolve, rotate, threePointArc, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// GT2 timing pulley on a closed 2 mm belt that drives a 40-tooth pulley. The axes are Z, the units are millimetres.
// The pitch, the pitch-line offset and the groove form are published figures. The belt length sets the centre distance.
// The flanges, the hubs, the set screws and the shafts are a display model.
interface DriveParams {
teeth?: number; // grooves of the drive pulley, 16 to 30
turn?: number; // degrees of drive pulley rotation; the belt and the driven pulley follow by the true ratio
cutaway?: number; // degrees of each top flange to cut away
}
type P2 = [number, number];
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 (2 mm GT2)
const PITCH = 2;
const PLD = 0.254; // the pitch line is this far outside the pulley
const GROOVE = { depth: 0.764, tip: 0.555, flank: 1, offset: 0.4, edge: 0.15 }; // three arcs: bottom, flank, top edge
const BELT = { teeth: 80, width: 6, height: 1.52, tooth: 0.76 };
const DRIVEN_TEETH = 40;
const SCREW = { radius: 1.5, minor: 2.459, pitch: 0.5, socket: 1.5 }; // M3 coarse thread, right hand, set screw with a 1.5 mm hexagon socket
// ---- display model
const FACE = 7; // toothed width between the flanges
const FLANGE = { height: 1, over: 1.9 };
const FIT = 0.9; // the belt tooth is this fraction of the groove
const DRIVE = { bore: 5, hub: 7, hubLength: 6.5, screw: 4, flat: 0.5 };
const DRIVEN = { bore: 8, hub: 9, hubLength: 7, screw: 4, flat: 0 };
const PLAY = 0.05; // radial play between a set screw and its tapped hole
const Z: P3 = [0, 0, 1];
const lathe = (pts: P2[], angle = 2 * Math.PI): Shape => {
const profile = own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z]))));
return unwrap(revolve(profile, { axis: Z, angle })) as Shape;
};
// One helical thread tooth about +Z, from z = from to z = to. Its crest passes the +X side at z = ref.
// tip > core is the thread on a core of the radius core. tip < core is the thread in a bore of the radius core.
// The loft is smooth: each flank is one helical face.
const SECTIONS = 12; // sections of the loft 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 outward = tip > core;
const root = outward ? core / SLACK : core * SLACK;
const crest = outward ? tip : tip / SLACK;
const half = 0.42 * pitch; // half width of the tooth at its root
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): [number, number, number] => [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; // loft is ruled by default
};
// A closed loop of arcs [from, via, to] and lines [from, to] in the plane z.
const loop = (parts: P2[][], z: number) =>
own(unwrap(wire(parts.map((p) => own(p.length === 3 ? threePointArc([p[0]![0], p[0]![1], z], [p[1]![0], p[1]![1], z], [p[2]![0], p[2]![1], z]) : line([p[0]![0], p[0]![1], z], [p[1]![0], p[1]![1], z]))))));
// Half of the groove outline: [x across the groove, y into the pulley]. Every arc is tangent to the next one.
const grooveArcs = (k: number): P2[][] => {
const { depth, tip, flank, offset, edge } = GROOVE;
const xe = Math.sqrt((flank + edge) * (flank + edge) - edge * edge) - offset; // the top edge starts here
const on = (a: number): P2 => [flank * Math.cos(a) - offset, flank * Math.sin(a)];
const a1 = Math.atan2(edge, xe + offset);
const a2 = Math.atan2(depth - tip, offset);
const b = (5 * Math.PI) / 4 + a1 / 2;
const right: P2[][] = [
[[xe, 0], [xe + edge * Math.cos(b), edge + edge * Math.sin(b)], on(a1)],
[on(a1), on((a1 + a2) / 2), on(a2)],
];
const left = right.map((arc) => arc.map(([x, y]): P2 => [-x, y]));
const all: P2[][] = [...left, [[-on(a2)[0], on(a2)[1]], [0, depth], on(a2)], ...right.map((arc) => [...arc].reverse()).reverse()];
return all.map((arc) => arc.map(([x, y]): P2 => [x * k, y * k]));
};
// The pitch line of an open belt drive: wrap on the drive pulley at the origin, run, wrap on the driven pulley at -X, run.
const pitchLine = (r1: number, r2: number, C: number) => {
const a = Math.PI / 2 - Math.asin((r2 - r1) / C);
const run = C * Math.sin(a);
const s1 = 2 * a * r1;
const s2 = s1 + run;
const s3 = s2 + (2 * Math.PI - 2 * a) * r2;
const length = s3 + run;
// The point at distance s along the line, moved by x along the belt and by y toward the inside.
const at = (s: number, x = 0, y = 0): P2 => {
const u = ((s % length) + length) % length;
const round = (cx: number, r: number, angle: number): P2 => {
const [c, n] = [Math.cos(angle), Math.sin(angle)];
return [cx + (r - y) * c - x * n, (r - y) * n + x * c];
};
const straight = (from: P2, t: P2, d: number): P2 => [from[0] + t[0] * (d + x) - t[1] * y, from[1] + t[1] * (d + x) + t[0] * y];
if (u < s1) return round(0, r1, u / r1 - a);
if (u < s2) return straight([r1 * Math.cos(a), r1 * Math.sin(a)], [-Math.sin(a), Math.cos(a)], u - s1);
if (u < s3) return round(-C, r2, a + (u - s2) / r2);
return straight([r2 * Math.cos(a) - C, -r2 * Math.sin(a)], [Math.sin(a), Math.cos(a)], u - s3);
};
return { a, s1, s2, s3, length, at };
};
// One pulley about the origin, first groove on +X: flanges, hub, grooves, two tapped holes with set screws and a shaft.
const pulley = (teeth: number, d: typeof DRIVE) => {
const od = (teeth * PITCH) / Math.PI / 2 - PLD;
const rf = od + FLANGE.over;
const [f, top, zh] = [FLANGE.height, FACE + FLANGE.height, -FLANGE.height - d.hubLength];
const b = d.bore / 2;
const lower = own(lathe([[b, zh], [d.hub - 0.5, zh], [d.hub, zh + 0.5], [d.hub, -f], [rf - 0.3, -f], [rf, -f + 0.3], [rf, -0.35], [od + 0.6, 0], [b, 0]]));
const upper = own(lathe([[b, FACE], [od + 0.6, FACE], [rf, FACE + 0.35], [rf, top - 0.3], [rf - 0.3, top], [b + 0.3, top], [b, top - 0.3]]));
// Toothed core: one outline with a groove for each tooth, extruded. No boolean cuts the grooves.
// The hub part and the top flange touch the core. They stay separate solids, which keeps the build fast.
const arcs = grooveArcs(1);
const xe = arcs[arcs.length - 1]![2]![0];
// A groove point on the rim: the depth goes along the radius and the width along the arc.
const onRim = ([x, y]: P2, i: number): P2 => {
const angle = (-2 * Math.PI * i) / teeth - x / (od - y);
return [(od - y) * Math.cos(angle), (od - y) * Math.sin(angle)];
};
const rim: P2[][] = [];
for (let i = 0; i < teeth; i++) {
for (const arc of arcs) rim.push(arc.map((p) => onRim(p, i)));
rim.push([onRim([xe, 0], i), onRim([0, 0], i + 0.5), onRim([-xe, 0], i + 1)]);
}
const bore = loop([[[b, 0], [0, b], [-b, 0]], [[-b, 0], [0, -b], [b, 0]]], 0);
const core = own(unwrap(extrude(own(unwrap(face(loop(rim, 0) as never, [bore as never]))), [0, 0, FACE])) as Shape);
const zs = zh / 2 - f / 2;
// Tapped holes and set screws are built along +Z, with z as the distance from the pulley axis, and then laid radial.
const radial = (s: Shape, deg: number): Shape => own(rotate(own(translate(own(rotate(s, 90, { axis: [0, 1, 0] })), [0, 0, zs])), deg, { axis: Z }) as Shape);
const tap = SCREW.radius + PLAY;
const rm = SCREW.minor / 2;
const edge = 0.42 * SCREW.pitch; // a tooth ends this far from the end of its thread
const drill = own(cylinder(tap, d.hub + 1));
const hub = own(unwrap(cutAll(lower, [0, 90].map((deg) => radial(drill, deg)))) as Shape);
// The thread in each hole: the mating tooth, half a pitch from the screw's.
const tapTooth = own(helixTooth(tap, rm + PLAY, SCREW.pitch, b + edge, Math.sqrt(d.hub * d.hub - tap * tap) - edge, SCREW.pitch / 2));
const tapTeeth = [0, 90].map((deg) => radial(tapTooth, deg));
// Set screws: a core with one helical tooth, a flat point and a hexagon socket. The first one sits on the shaft flat.
const rh = SCREW.socket / Math.sqrt(3);
const screws = [0, 90].map((deg) => {
const seat = d.bore / 2 - (deg === 0 ? d.flat : 0);
const hex = Array.from({ length: 6 }, (_, i): P3 => [rh * Math.cos((i * Math.PI) / 3), rh * Math.sin((i * Math.PI) / 3), seat + d.screw - 1.6]);
const socket = own(unwrap(extrude(own(unwrap(polygon(hex))), [0, 0, 1.7])));
const core = own(unwrap(cut(own(cylinder(rm, d.screw, { at: [0, 0, seat] })), socket)) as Shape);
return radial(own(compound([core, own(helixTooth(rm, SCREW.radius, SCREW.pitch, seat + edge, seat + d.screw - edge, 0))]) as Shape), deg);
});
// Shaft: round, with a flat for the first set screw when the pulley has one.
const r = d.bore / 2;
const fx = r - d.flat;
const fy = Math.sqrt(r * r - fx * fx);
const section = d.flat > 0 ? loop([[[fx, -fy], [-r, 0], [fx, fy]], [[fx, fy], [fx, -fy]]], zh - 9) : loop([[[r, 0], [0, r], [-r, 0]], [[-r, 0], [0, -r], [r, 0]]], zh - 9);
const shaft = own(unwrap(extrude(own(unwrap(face(section as never))), [0, 0, top + 2 - (zh - 9)])) as Shape);
return { core, hub, tapTeeth, upper, screws, shaft, od, rf, top };
};
function drive({ teeth = 20, turn = 0, cutaway = 150 }: DriveParams = {}) {
const n1 = Math.round(Math.min(30, Math.max(16, teeth)));
const r1 = (n1 * PITCH) / Math.PI / 2;
const r2 = (DRIVEN_TEETH * PITCH) / Math.PI / 2;
// Find the centre distance that makes the pitch line as long as the belt.
let [lo, hi] = [r2 - r1 + 1, (BELT.teeth * PITCH) / 2];
for (let i = 0; i < 60; i++) {
const mid = (lo + hi) / 2;
if (pitchLine(r1, r2, mid).length < BELT.teeth * PITCH) lo = mid;
else hi = mid;
}
const C = (lo + hi) / 2;
const line2 = pitchLine(r1, r2, C);
const { a, s1, s2, s3, length, at } = line2;
// The kernel measures the pitch line: two arcs and two straight runs.
const mid = (from: number, to: number) => [at(from), at((from + to) / 2), at(to - 1e-9)];
const measured = unwrap(measureLength(loop([mid(0, s1), [at(s1), at(s2 - 1e-9)], mid(s2, s3), [at(s3), at(length - 1e-9)]], 0)));
// Belt: the back is the pitch line moved out. The inside is one tooth for each pitch, joined by lands.
const back = BELT.height - BELT.tooth - PLD;
const out = (s: number) => at(s, 0, -back);
const outer = loop([
[out(0), out(s1 / 2), out(s1 - 1e-9)], [out(s1), out(s2 - 1e-9)], [out(s2), out((s2 + s3) / 2), out(s3 - 1e-9)], [out(s3), out(length - 1e-9)],
], 0);
const s0 = PITCH / 2 + (turn / 360) * n1 * PITCH;
const tooth = grooveArcs(FIT);
const xe = tooth[tooth.length - 1]![2]![0];
const inner: P2[][] = [];
for (let j = 0; j < BELT.teeth; j++) {
const s = s0 + j * PITCH;
for (const arc of tooth) inner.push(arc.map(([x, y]) => at(s, x, PLD + y)));
const land = [at(s, xe, PLD), at(s + PITCH / 2, 0, PLD), at(s + PITCH, -xe, PLD)];
const [p, m, e] = [land[0]!, land[1]!, land[2]!];
const bend = Math.abs((m[0] - p[0]) * (e[1] - p[1]) - (m[1] - p[1]) * (e[0] - p[0]));
inner.push(bend < 1e-7 ? [p, e] : land);
}
const z0 = (FACE - BELT.width) / 2;
const belt = unwrap(extrude(own(unwrap(face(outer as never, [loop(inner, 0) as never]))), [0, 0, BELT.width])) as Shape;
const lifted = translate(belt, [0, 0, z0]) as Shape;
belt.delete();
// Place each pulley so that a groove is under a belt tooth, then cut a part of its top flange away.
const place = (p: ReturnType<typeof pulley>, x: number, radians: number) => {
const move = (s: Shape): Shape => own(translate(own(rotate(s, (radians * 180) / Math.PI, { axis: Z })), [x, 0, 0]) as Shape);
const sweep = (Math.max(cutaway, 1) * Math.PI) / 180;
const wedge = own(translate(own(rotate(own(lathe([[0, FACE], [p.rf + 1, FACE], [p.rf + 1, p.top + 1], [0, p.top + 1]], sweep)), -cutaway / 2, { axis: Z })), [x, 0, 0]) as Shape);
const flange = move(p.upper);
const body = compound([move(p.core), move(p.hub), ...p.tapTeeth.map(move), cutaway > 0 ? own(unwrap(cut(flange, wedge)) as Shape) : flange]) as Shape;
return { body, screws: p.screws.map(move), shaft: move(p.shaft) };
};
const small = place(pulley(n1, DRIVE), 0, s0 / r1 - a);
const large = place(pulley(DRIVEN_TEETH, DRIVEN), -C, a + (s0 - s2) / r2);
return {
pulleys: [small.body, large.body],
screws: compound([...small.screws, ...large.screws]) as Shape,
shafts: compound([small.shaft, large.shaft]) as Shape,
belt: lifted,
facts: { measured, C, ratio: DRIVEN_TEETH / n1 },
};
}
const part = freeing(() => drive());
console.log(
'Pitch line: ' + part.facts.measured.toFixed(2) + ' mm by the kernel. The belt has ' + BELT.teeth + ' teeth at ' + PITCH + ' mm, which is ' + BELT.teeth * PITCH +
' mm. Centre distance ' + part.facts.C.toFixed(2) + ' mm, ratio ' + part.facts.ratio.toFixed(2) + ' to 1.',
);
export default [
...part.pulleys.map((s) => color(s, '#c3c9d1')),
color(part.belt, '#12b5b0'),
color(part.screws, '#48515c'),
color(part.shafts, '#8d96a0'),
];Functions used
compound cut cutAll cylinder extrude face line loft measureLength polygon revolve rotate threePointArc translate unwrap wire color