Modular Coolant Hose

A modular coolant hose of the 1/4 inch system: ball-and-socket segments that snap together, from a threaded connector in a block to a round nozzle. A boolean cut opens the connector and the first two segments to show the joints, and the 1/4-18 taper pipe thread of the connector in the mating thread of the block. The bend parameter turns each joint about the centre of its ball. The pipe thread is the published one. All other dimensions are a display model, close to the sizes that sellers list for this system.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { box, clone, compound, cut, extrude, face, fuse, line, loft, polygon, revolve, rotate, threePointArc, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Modular coolant hose, 1/4 inch system: ball-and-socket segments from a threaded connector to a round nozzle. In cutaway.
// The connector points up Z, the chain bends about X, and the units are millimetres.
// The pipe thread of the connector is the published 1/4-18 taper thread, as a true helix in the mating thread of the block.
// All other dimensions are a display model, close to the sizes that sellers list for this system.
interface HoseParams {
segments?: number; // segments between the connector and the nozzle
bend?: number; // -1..1, where 1 is the tightest bend
cutaway?: number; // degrees opened toward +X on the connector and the first segments (0 = closed)
}
type P2 = [number, number]; // [r, z]
type P3 = [number, number, number];
type Shape = ReturnType<typeof box>;
// 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 (1/4-18 taper pipe thread)
const THREAD = { major: 6.858, pitch: 25.4 / 18, length: 12 }; // radius at the hexagon, 18 threads per inch
const TAPER = 1 / 32; // radius for each millimetre of length: 1 in 16 on the diameter
// ---- display model (no source page could be opened to confirm the first four figures)
const BORE = 6.7; // smallest inside diameter
const OUTSIDE = 16.3; // outside diameter of a socket
const PITCH = 15; // length that one segment adds
const BEND_DIAMETER = 50; // smallest diameter of a full bend
const BALL = 7.2; // radius of the ball and of the socket that holds it
const WALL = 0.9;
const LIP = 20; // degrees from the equator to the open end of a ball
const RIM = 15; // degrees that a socket closes over the ball
const NECK = 52; // degrees from the equator to the neck of a ball
const SEAT = 55; // degrees from the equator to the bottom of a socket
const DEPTH = 0.6 * THREAD.pitch; // thread depth
const PLAY = 0.1; // radial play between the two threads
const HEX = { flats: 17, height: 6 };
const NOZZLE = { length: 24, orifice: 6.35 };
const SECTIONED = 2; // segments that the cutaway opens
const d2r = Math.PI / 180;
const onBall = (deg: number, z0: number, up: 1 | -1): P2 => [BALL * Math.cos(deg * d2r), z0 + up * BALL * Math.sin(deg * d2r)];
// 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;
});
if (from !== start) 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 on a taper, from z = from to z = to. Its crest passes the +X side at z = ref.
// core and tip are radii at z = 0, and both grow by TAPER for each millimetre of z. tip > core is the thread of
// the connector, tip < core is the thread in the block. A right-hand thread.
const FACETS = 12; // sections of the smooth loft in each turn. Each flank is one helical face
const SLACK = 0.998; // keeps the tooth a hair clear of its core or its bore
const helixTooth = (core: number, tip: number, from: number, to: number, ref: number): Shape => {
const half = 0.42 * THREAD.pitch;
const n = Math.max(2, Math.round(((to - from) / THREAD.pitch) * FACETS));
const sections = Array.from({ length: n + 1 }, (_, j) => {
const z = from + ((to - from) * j) / n;
const a = 2 * Math.PI * ((z - ref) / THREAD.pitch);
const root = tip > core ? (core + TAPER * (z + half)) / SLACK : (core + TAPER * (z - half)) * SLACK; // clear of the core, or of the bore
const crest = tip > core ? tip + TAPER * z : (tip + TAPER * z) / SLACK;
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 own(unwrap(loft(sections, { ruled: false }))) as Shape;
};
function hose({ segments = 6, bend = 0.4, cutaway = 140 }: HoseParams = {}) {
const bore = BORE / 2;
const outer = OUTSIDE / 2;
const count = Math.max(1, Math.round(segments));
const tightest = (2 * Math.asin(PITCH / BEND_DIAMETER)) / d2r; // degrees at each joint on the tightest bend
const step = Math.sign(bend) * Math.min(Math.abs(bend) * tightest, tightest, 180 / (count + 1)); // a long chain stops at a half turn
// Socket: centred on z = 0, open toward -Z. It closes a little past the equator of the ball, so the joint snaps.
const rim = onBall(RIM, 0, -1);
const seat = onBall(SEAT, 0, 1);
const socket: (P2 | [P2, P2])[] = [[rim[0] + 0.6, rim[1]], [[outer - 0.15, rim[1] + 0.2], [outer, rim[1] + 0.7]], [outer, 4.4]];
const cavity: (P2 | [P2, P2])[] = [seat, [onBall(0, 0, 1), rim]];
// Ball: centred on z0, open toward +Z.
const ball = (z0: number, up: 1 | -1) => ({
lipOut: onBall(LIP, z0, up),
lipIn: [onBall(LIP, z0, up)[0] - WALL, onBall(LIP, z0, up)[1]] as P2,
neck: onBall(NECK, z0, up === 1 ? -1 : 1),
equator: onBall(0, z0, up),
});
// ---- one segment: socket below, ball above
const b = ball(PITCH, 1);
const segment = own(lathe(rim, [
...socket, [b.neck[0] + 0.05, PITCH - 6.3], b.neck, [b.equator, b.lipOut], b.lipIn,
[bore, PITCH - 4.2], [bore, PITCH - 7.6], ...cavity,
]));
// ---- nozzle: socket below, tapered tip above
const tipR = NOZZLE.orifice / 2;
const nozzle = own(lathe(rim, [...socket, [tipR + 1.3, NOZZLE.length], [tipR, NOZZLE.length], [tipR, NOZZLE.length - 6], ...cavity]));
// ---- connector: ball above, hex and pipe thread below
const c = ball(0, 1);
const zHex = -7;
const zThread = zHex - HEX.height;
const zEnd = zThread - THREAD.length;
// The thread radii are given at the hexagon. They get smaller toward the end of the connector.
const major = THREAD.major - TAPER * zThread; // radius at z = 0 of the cone that the crests lie on
const minor = major - DEPTH;
const flank = 0.42 * THREAD.pitch;
const stem = own(lathe(c.lipIn, [c.lipOut, [c.equator, c.neck], [c.neck[0] + 0.05, zHex], [minor + TAPER * zThread, zHex], [minor + TAPER * zThread, zThread], [minor + TAPER * zEnd, zEnd], [0, zEnd], [0, c.lipIn[1]]]));
const tooth = helixTooth(minor, major, zEnd + flank, zThread - flank, 0);
const rc = HEX.flats / Math.sqrt(3);
const flat = 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), zThread]))));
const solid = own(unwrap(fuse(stem, own(unwrap(extrude(flat, HEX.height)) as Shape))) as Shape);
const waterway = own(lathe([0, zEnd - 1], [[bore, zEnd - 1], [bore, -3.5], [c.lipIn[0], c.lipIn[1]], [c.lipIn[0], c.lipIn[1] + 1], [0, c.lipIn[1] + 1]]));
const connector = own(unwrap(cut(solid, waterway)) as Shape);
// ---- block that the connector screws into
const blockH = THREAD.length + 4;
const blank = own(box(26, 26, blockH, { at: [0, 0, zThread - blockH / 2] }));
const [zTop, zBottom] = [zThread + 1, zThread - blockH - 1];
const tapered = own(lathe([0, zBottom], [[major + PLAY + TAPER * zBottom, zBottom], [major + PLAY + TAPER * zTop, zTop], [0, zTop]]));
const block = own(unwrap(cut(blank, tapered)) as Shape);
const tapped = helixTooth(major + PLAY, minor + PLAY, zThread - blockH + flank, zThread - flank, THREAD.pitch / 2); // half a pitch from the connector
// Cutaway: a wedge about the axis of each part, centred on +X. The bend is about X, so the cut stays toward +X.
// The other segments and the nozzle stay whole.
const sweep = (Math.max(cutaway, 1) * Math.PI) / 180;
const wedge = own(rotate(own(lathe([0, -60], [[60, -60], [60, 60], [0, 60]], sweep)), -cutaway / 2) as Shape);
const open = (part: Shape): Shape => (cutaway > 0 ? (unwrap(cut(part, wedge)) as Shape) : (unwrap(clone(part)) as Shape));
const link = own(open(segment));
// Pose: each joint turns about the centre of its ball.
let centre: P3 = [0, 0, 0];
const pose = (part: Shape, joint: number): Shape => {
const a = joint * step;
const placed = translate(own(rotate(part, a, { axis: [1, 0, 0] }) as Shape), centre) as Shape;
centre = [centre[0], centre[1] - PITCH * Math.sin(a * d2r), centre[2] + PITCH * Math.cos(a * d2r)];
return placed;
};
const chain = Array.from({ length: count }, (_, i) => own(pose(i < SECTIONED ? link : segment, i + 1)));
const every = (rest: number): Shape[] => {
const picked = chain.filter((_, i) => i % 2 === rest);
return picked.length > 0 ? [compound(picked) as Shape] : [];
};
return { teal: every(0), white: every(1), nozzle: pose(nozzle, count + 1), connector: compound([own(open(connector)), own(open(tooth))]) as Shape, block: compound([own(open(block)), own(open(tapped))]) as Shape };
}
const part = freeing(() => hose());
export default [
...part.teal.map((links) => color(links, '#12b5b0')),
...part.white.map((links) => color(links, '#f5f2ea')),
color(part.nozzle, '#ff5a1f'),
color(part.connector, '#ff5a1f'),
color(part.block, '#c3c9d1'),
];Functions used
box clone compound cut extrude face fuse line loft polygon revolve rotate threePointArc translate unwrap wire color