Fluted Star Knob

A fluted star knob with a moulded-in steel hub and a tapped blind bore, on a hex screw that clamps a slotted bar, opened by a boolean cut. The grip diameter, the heights, the hub diameter, the thread and its depth are datasheet figures for four sizes. The flute outline, the hub anchor, the screw, the washer and the bar are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { box, clone, compound, cut, cutAll, cylinder, extrude, face, fuse, interpolateCurve, intersect, line, loft, polygon, revolve, rotate, threePointArc, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Fluted star knob with a moulded-in steel hub, on a hex screw that clamps a slotted bar. In cutaway.
// The axis is Z, the face of the hub is at z = 0, and the units are millimetres.
// The knob dimensions are datasheet figures. The grip outline, the hub anchor and the clamped parts are a display model.
interface KnobParams {
size?: 32 | 40 | 50 | 63; // grip diameter d1
flutes?: number; // flutes around the grip
cutaway?: number; // degrees opened toward +X (0 = closed)
}
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 (star knob with a protruding steel hub and a tapped blind bore)
const SIZES = {
32: { thread: 6, hub: 12, h1: 21, h2: 10, h3: 8.5, depth: 12 },
40: { thread: 8, hub: 14, h1: 26, h2: 13, h3: 10, depth: 14 },
50: { thread: 10, hub: 18, h1: 34, h2: 17, h3: 10, depth: 18 },
63: { thread: 12, hub: 20, h1: 42, h2: 21, h3: 14, depth: 22 },
}; // h1 = total height, h2 = hub face to grip, h3 = steel that shows, depth = least thread depth
const DATASHEET_FLUTES = 7;
// ---- display model
const SCREWS = {
6: { pitch: 1, flats: 10, head: 4, washer: 12, plate: 1.6 },
8: { pitch: 1.25, flats: 13, head: 5.3, washer: 16, plate: 1.6 },
10: { pitch: 1.5, flats: 16, head: 6.4, washer: 20, plate: 2 },
12: { pitch: 1.75, flats: 18, head: 7.5, washer: 24, plate: 2.5 },
}; // metric coarse hex screw (right hand thread) and plain washer
const PLAY = 0.08; // radial play between the screw thread and the thread in the hub
const FLUTE = 0.24; // flute depth, a part of the grip radius
const BAR = { thick: 8, slot: 0.9 }; // slot length, a part of the grip diameter
// A closed profile in the (r, z) half-plane, revolved about Z. A [mid, end] pair is an arc.
const lathe = (start: P2, path: (P2 | [P2, P2])[], angle = 2 * Math.PI): Shape => {
const at = ([r, z]: P2): P3 => [r, 0, z];
let from = start;
const edges = path.map((step) => {
const arc = typeof step[0] !== 'number';
const to = (arc ? step[1] : step) as P2;
const edge = own(arc ? threePointArc(at(from), at(step[0] as P2), at(to)) : line(at(from), at(to)));
from = to;
return edge;
});
edges.push(own(line(at(from), at(start))));
const profile = own(unwrap(face(own(unwrap(wire(edges))) as never)));
return unwrap(revolve(profile, { axis: [0, 0, 1], angle })) as Shape;
};
// A 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.
// skip leaves out that many degrees of each turn, centred on +X: the thread of a part in cutaway.
// 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, skip = 0): 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 span = (z0: number, z1: number): Shape => {
const n = Math.max(3, Math.ceil(((z1 - z0) / pitch) * SECTIONS));
const sections = Array.from({ length: n + 1 }, (_, j) => {
const z = z0 + ((z1 - z0) * 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 own(unwrap(loft(sections, { ruled: false })) as Shape); // loft is ruled by default
};
if (skip <= 0) return [span(from, to)];
const lost = (skip / 720) * pitch; // height of half of the part that each turn loses
const spans: Shape[] = [];
for (let k = Math.floor((from - ref) / pitch) - 1; ref + k * pitch < to; k++) {
const [z0, z1] = [Math.max(from, ref + k * pitch + lost), Math.min(to, ref + (k + 1) * pitch - lost)];
if (z1 - z0 > 0.05 * pitch) spans.push(span(z0, z1));
}
return spans;
};
function knob({ size = 40, flutes = DATASHEET_FLUTES, cutaway = 100 }: KnobParams = {}) {
const s = SIZES[size];
const screw = SCREWS[s.thread as 6 | 8 | 10 | 12];
const R = size / 2;
const hubR = s.hub / 2;
// ---- grip: a fluted outline, extruded, then trimmed by a domed and rounded revolve
const count = Math.max(3, Math.round(flutes));
const outline = Array.from({ length: count * 4 }, (_, i): P3 => {
const a = (i * Math.PI) / (count * 2);
const r = R * (1 - (FLUTE * (1 - Math.cos(count * a))) / 2);
return [r * Math.cos(a), r * Math.sin(a), s.h2];
});
const loop = own(unwrap(wire([own(unwrap(interpolateCurve(outline, { periodic: true })))])));
const prism = own(unwrap(extrude(own(unwrap(face(loop as never))), s.h1 - s.h2)) as Shape);
const crown = 0.12 * R; // drop of the dome at the shoulder
const rim = 0.2 * R;
const top = s.h1;
const dome = own(lathe([0, s.h2], [
[R - rim, s.h2],
[[R - 0.3 * rim, s.h2 + 0.3 * rim], [R, s.h2 + rim]],
[R, top - crown - rim],
[[R - 0.3 * rim, top - crown - 0.3 * rim], [R - rim, top - crown]],
[[(R - rim) * 0.5, top - crown * 0.25], [0, top]],
]));
const mark = own(lathe([0.36 * R, top - 0.8], [[0.42 * R, top - 0.8], [0.42 * R, top], [0.36 * R, top]])); // ring groove in the top of the dome
const head = own(unwrap(cut(own(unwrap(intersect(prism, dome)) as Shape), mark)) as Shape);
const boss = own(lathe([0, s.h3], [[hubR + 2.5, s.h3], [hubR + 4, s.h2 + 1], [0, s.h2 + 1]]));
// ---- steel hub: a groove and a flange anchor it in the plastic
const zi = s.depth + 4;
const anchor = own(lathe([0, 0], [
[hubR - 0.5, 0], [hubR, 0.5], [hubR, s.h3 + 1.6], [hubR - 1.2, s.h3 + 2.2], [hubR - 1.2, s.h3 + 3.6],
[hubR + 1.6, s.h3 + 4.2], [hubR + 1.6, zi - 0.8], [hubR + 0.8, zi], [0, zi],
]));
const body = own(unwrap(cut(own(unwrap(fuse(head, boss)) as Shape), anchor)) as Shape);
// Tapped blind bore: bored to the major diameter, with one helical tooth. The screw carries the mating tooth, half a pitch away.
const major = s.thread / 2;
const minor = major - 0.54 * screw.pitch;
const tap = major + PLAY;
const edge = 0.42 * screw.pitch; // a tooth ends this far from the end of its thread
const tapped = own(lathe([0, 0], [[tap, 0], [tap, s.depth], [minor, s.depth], [0, s.depth + 0.6 * minor]]));
const hub = own(unwrap(cut(anchor, tapped)) as Shape);
const tapTeeth = helixTooth(tap, minor + PLAY, screw.pitch, edge, s.depth - edge, screw.pitch / 2, cutaway); // built without the part in the cutaway
// ---- clamped parts under the knob: a plain washer, a slotted bar and a hex screw from below
const zBar = -screw.plate;
const zHead = zBar - BAR.thick;
const washer = own(lathe([major + 0.2, zBar], [[screw.washer / 2, zBar], [screw.washer / 2, 0], [major + 0.2, 0]]));
const slotR = major + 0.5;
const blank = own(box(0.75 * size, 1.7 * size, BAR.thick, { at: [0, 0, zHead + BAR.thick / 2] }));
const half = (BAR.slot * size) / 2 - slotR;
const slot = [
own(box(2 * slotR, 2 * half, BAR.thick + 2, { at: [0, 0, zHead + BAR.thick / 2] })),
own(cylinder(slotR, BAR.thick + 2, { at: [0, half, zHead - 1] })),
own(cylinder(slotR, BAR.thick + 2, { at: [0, -half, zHead - 1] })),
];
const bar = own(unwrap(cutAll(blank, slot)) as Shape);
// Hex screw, threaded to the head. Its chamfered end stops at 0.7 of the thread depth.
const end = 0.7 * s.depth;
const shank = own(lathe([0, zHead], [[minor, zHead], [minor, end - 0.5], [minor - 0.5, end], [0, end]]));
const thread = helixTooth(minor, major, screw.pitch, zHead + screw.pitch, end - 0.5 - edge, 0);
const rc = screw.flats / Math.sqrt(3);
const hexFace = own(unwrap(polygon([0, 1, 2, 3, 4, 5].map((i): P3 => [rc * Math.cos((i * Math.PI) / 3), rc * Math.sin((i * Math.PI) / 3), zHead - screw.head]))));
const hexHead = own(unwrap(extrude(hexFace, screw.head)) as Shape);
const bevel = own(lathe([0, zHead - screw.head], [[0.82 * rc, zHead - screw.head], [rc, zHead - screw.head + 0.1 * rc], [rc, zHead], [0, zHead]]));
const bolt = compound([own(unwrap(fuse(shank, own(unwrap(intersect(hexHead, bevel)) as Shape))) as Shape), ...thread]) as Shape;
// Cutaway: a wedge about Z, centred on +X. The screw stays whole.
const sweep = (Math.max(cutaway, 1) * Math.PI) / 180;
const far = 4 * size;
const wedge = own(rotate(own(lathe([0, -far], [[far, -far], [far, far], [0, far]], sweep)), -cutaway / 2) as Shape);
const open = (part: Shape): Shape => (cutaway > 0 ? (unwrap(cut(part, wedge)) as Shape) : (unwrap(clone(part)) as Shape));
return { body: open(body), hub: compound([own(open(hub)), ...tapTeeth]) as Shape, washer: open(washer), bar: unwrap(clone(bar)) as Shape, bolt };
}
const part = freeing(() => knob());
export default [
color(part.body, '#12b5b0'),
color(part.hub, '#c3c9d1'),
color(part.washer, '#f5f2ea'),
color(part.bar, '#8a939e'),
color(part.bolt, '#d3a956'),
];Functions used
box clone compound cut cutAll cylinder extrude face fuse interpolateCurve intersect line loft polygon revolve rotate threePointArc unwrap wire color