Flanged Pipe Tee

A Class 125 ductile iron flanged tee, NPS 2, bolted to three threaded companion flanges with full face gaskets and hex bolts, and opened by a boolean cut. The bolts and nuts have a true 5/8-11 UNC helix, and each pipe turns into its flange on a taper pipe thread. The centre to face length, the wall, the flange drilling, the bolt size, the thread pitches and the weight are published figures. The kernel measures the volume of the tee: 17.2 lb of iron against 20 lb in the catalogue. The fillets, the gaskets, the hex sizes and the pipe stubs are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { clone, compound, cut, cutAll, cylinder, extrude, fuse, intersect, line, loft, measureVolume, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Class 125 ductile iron flanged tee, bolted to three threaded companion flanges, in cutaway.
// The run is along Y and the branch is up Z. The units are millimetres.
// The tee, flange and bolt sizes, the threads and the weight are published figures. The rest is a display model.
interface TeeParams {
nps?: 2 | 3 | 4; // nominal pipe size, inches
cutaway?: number; // degrees opened toward +X (0 = closed)
explode?: number; // 0..1 pulls the three joints apart. Each bolt turns out of its nut, one turn for each pitch
}
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 (inches and pounds, from a Class 125/150 flanged fitting catalogue)
const IN = 25.4;
const SIZES = {
2: { face: 4.5, wall: 0.31, od: 6, circle: 4.75, thick: 0.625, bolts: 4, boltLength: 2.5, hub: 1, pipe: 2.38, pounds: 20 },
3: { face: 5.5, wall: 0.38, od: 7.5, circle: 6, thick: 0.75, bolts: 4, boltLength: 2.5, hub: 1.1875, pipe: 3.5, pounds: 40 },
4: { face: 6.5, wall: 0.5, od: 9, circle: 7.5, thick: 0.9375, bolts: 8, boltLength: 3, hub: 1.3125, pipe: 4.5, pounds: 65 },
}; // face = centre to flange face, hub = companion flange length
const HOLE = 0.75 * IN;
const BOLT = 0.625 * IN;
const UNC = { pitch: IN / 11, minor: 0.5266 * IN }; // 5/8-11 UNC bolt thread, right hand
const NPT = { tpi: { 2: 11.5, 3: 8, 4: 8 }, depth: 0.8, taper: 1 / 16 }; // taper pipe thread: depth as a part of the pitch, taper on the diameter
const IRON = 7.1e-3; // ductile iron, grams per cubic millimetre
const POUND = 453.6; // grams
// ---- display model
const FILLET = 8; // cast radius behind each flange
const GASKET = 3.2; // full face gasket
const HEX = { flats: 23.8, head: 10.7, nut: 13.9, thread: 38 }; // 5/8 hex bolt and nut, thread length
const STUB = 35; // pipe length past each companion flange
const PIPE_WALL = { 2: 3.9, 3: 5.5, 4: 6 };
const GAP = 70; // travel of a companion flange at explode = 1
const SHOWN = 8; // pipe thread that shows past the hub
const PLAY = { bolt: 0.1, pipe: 0.15 }; // radial play between mating threads
// A closed profile in the (r, z) half-plane, revolved about Z.
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: [0, 0, 1], angle })) as Shape;
};
const arc = (cr: number, cz: number, rad: number, from: number, to: number): P2[] =>
[0, 1, 2, 3, 4].map((i): P2 => {
const a = ((from + ((to - from) * i) / 4) * Math.PI) / 180;
return [cr + rad * Math.cos(a), cz + rad * Math.sin(a)];
});
// A helical thread tooth about +Z, from z = from to z = to. Its crest passes the +X side at z = ref.
// core and tip are radii at z = 0, and slope adds radius for each unit of z (a taper thread).
// tip > core is the thread on a core. tip < core is the thread in a bore.
// skip leaves out that many degrees of each turn, centred on +X: the thread of a part in cutaway.
// skip = 0 makes one piece for each turn, with the joints on the -X side: a long tooth on a large pipe stays exact.
// The loft is smooth: 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, pitch: number, from: number, to: number, ref: number, slope = 0, skip = -1, sections = 12): Shape[] => {
const [kc, kt] = tip > core ? [1 / SLACK, 1] : [SLACK, 1 / 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 outlines = Array.from({ length: n + 1 }, (_, j) => {
const z = z0 + ((z1 - z0) * j) / n;
const a = 2 * Math.PI * ((z - ref) / pitch);
const at = (r0: number, k: number, dz: number): P3 => [(r0 + slope * (z + dz)) * k * Math.cos(a), (r0 + slope * (z + dz)) * k * Math.sin(a), z + dz];
const pts = [at(core, kc, -half), at(tip, kt, 0), at(core, kc, half)];
return own(unwrap(wire(pts.map((p, i) => own(line(p, pts[(i + 1) % 3]!))))));
});
return own(unwrap(loft(outlines, { 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 first = skip > 0 ? ref : ref + pitch / 2;
const spans: Shape[] = [];
for (let k = Math.floor((from - first) / pitch) - 1; first + k * pitch < to; k++) {
const [z0, z1] = [Math.max(from, first + k * pitch + lost), Math.min(to, first + (k + 1) * pitch - lost)];
if (z1 - z0 > 0.05 * pitch) spans.push(span(z0, z1));
}
return spans;
};
// A hex prism on Z with a 30 degree chamfer on its corners.
const hex = (height: number, both: boolean): Shape => {
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), 0]))));
const prism = own(unwrap(extrude(flat, height)) as Shape);
const c = rc - 0.47 * HEX.flats;
const d = c * 0.58;
const low: P2[] = both ? [[rc - c, 0], [rc, d]] : [[rc, 0]];
return unwrap(intersect(prism, own(lathe([[0, 0], ...low, [rc, height - d], [rc - c, height], [0, height]])))) as Shape;
};
function flangedTee({ nps = 2, cutaway = 90, explode = 0 }: TeeParams = {}) {
const s = SIZES[nps];
const H = s.face * IN;
const T = s.thick * IN;
const rf = (s.od * IN) / 2;
const bore = (nps * IN) / 2; // the bore of the fitting is the nominal size
const rb = bore + s.wall * IN;
const gap = GAP * Math.min(Math.max(explode, 0), 1);
const angles = Array.from({ length: s.bolts }, (_, i) => ((i + 0.5) * 360) / s.bolts);
const rc = (s.circle * IN) / 2;
// Each joint is built on Z with the tee flange face at z = 0, then put on its end of the tee.
const place = (part: Shape, end: number): Shape => {
if (end === 0) return translate(part, [0, 0, H]) as Shape;
const turned = own(rotate(part, end === 1 ? -90 : 90, { axis: [1, 0, 0] }) as Shape);
return translate(turned, [0, end === 1 ? H : -H, 0]) as Shape;
};
const ends = [0, 1, 2];
const ring = (part: Shape, r: number): Shape[] => angles.map((a) => own(rotate(own(translate(part, [r, 0, 0]) as Shape), a) as Shape));
// ---- tee body: two revolved castings, fused, then bored and drilled
const neck = arc(rb + FILLET, H - T - FILLET, FILLET, 180, 90);
const branch = own(lathe([[0, 0], [rb, 0], ...neck, [rf, H - T], [rf, H], [0, H]]));
const foot = arc(rb + FILLET, -H + T + FILLET, FILLET, 270, 180);
const run = own(rotate(own(lathe([[0, -H], [rf, -H], [rf, -H + T], ...foot, ...neck, [rf, H - T], [rf, H], [0, H]])), 90, { axis: [1, 0, 0] }) as Shape);
const casting = own(unwrap(fuse(run, branch)) as Shape);
const drill = own(cylinder(HOLE / 2, T + 2, { at: [0, 0, -T - 1] }));
const holes = ends.flatMap((end) => ring(drill, rc).map((h) => own(place(h, end))));
const bores = [own(cylinder(bore, 2 * H + 2, { at: [0, -H - 1, 0], axis: [0, 1, 0] })), own(cylinder(bore, H + 1))];
const tee = own(unwrap(cutAll(casting, [...bores, ...holes])) as Shape);
const pounds = (unwrap(measureVolume(tee)) * IRON) / POUND;
// ---- one joint: gasket, threaded companion flange, pipe stub, hex bolts and nuts
const pipeR = (s.pipe * IN) / 2;
const z0 = GASKET + gap; // back face of the companion flange
const zh = z0 + s.hub * IN;
const hubR = pipeR + 0.3 * IN;
const gasketBlank = own(lathe([[bore, 0], [rf, 0], [rf, GASKET], [bore, GASKET]]));
// Taper pipe thread: the crest is at the pipe diameter where the thread runs out, and smaller toward the pipe end.
const pp = IN / NPT.tpi[nps];
const slope = NPT.taper / 2;
const [zEnd, zOut] = [z0 + 3, zh + SHOWN]; // the pipe end, and where its thread runs out
const crest0 = pipeR - slope * zOut; // radii at z = 0
const root0 = crest0 - NPT.depth * pp;
const tapAt = (z: number): number => crest0 + PLAY.pipe + slope * z; // the bore of the flange
const flangeBlank = own(lathe([[tapAt(z0), z0], [rf, z0], [rf, z0 + T], [hubR + 4, z0 + T], [hubR, z0 + T + 4], [hubR, zh - 2], [hubR - 2, zh], [tapAt(zh), zh]]));
const through = ring(own(cylinder(HOLE / 2, zh + 2, { at: [0, 0, -1] })), rc);
const gasket = own(translate(own(unwrap(cutAll(gasketBlank, through)) as Shape), [0, 0, gap * 0.45]) as Shape);
const flange = own(unwrap(cutAll(flangeBlank, through)) as Shape);
const inner = pipeR - PIPE_WALL[nps];
const pipe = own(lathe([[inner, zEnd], [root0 + slope * zEnd, zEnd], [root0 + slope * zOut, zOut], [pipeR, zOut + pp], [pipeR, zh + STUB], [inner, zh + STUB]]));
// The pipe tooth and the flange tooth are half a pitch apart. In cutaway they are built without the part in the wedge.
const edgeP = 0.42 * pp; // a tooth ends this far from the end of its thread
const pipeTeeth = helixTooth(root0, crest0, pp, zEnd + edgeP, zOut - edgeP, z0, slope, Math.max(cutaway, 0), 16);
const flangeTeeth = helixTooth(crest0 + PLAY.pipe, root0 + PLAY.pipe, pp, z0 + edgeP, zh - edgeP, z0 + pp / 2, slope, Math.max(cutaway, 0), 16);
// Hex bolt: a plain shank, then a core with one helical tooth over the thread length. The seat of the head is at z = 0.
const major = BOLT / 2;
const rm = UNC.minor / 2;
const edge = 0.42 * UNC.pitch;
const tip = -s.boltLength * IN;
const shank = own(lathe([[0, tip], [rm - 1, tip], [rm, tip + 1], [rm, tip + HEX.thread], [major, tip + HEX.thread], [major, 0], [0, 0]]));
const headed = own(unwrap(fuse(shank, own(hex(HEX.head, false)))) as Shape);
const threaded = own(compound([headed, ...helixTooth(rm, major, UNC.pitch, tip + 1 + edge, tip + HEX.thread - edge, 0)]) as Shape);
// Nut: bored to the major diameter, with the mating tooth half a pitch from the bolt's.
const tap = major + PLAY.bolt;
const [zBolt, zNut] = [GASKET + T, -T - HEX.nut]; // where the bolt and the nut sit in the closed joint
const nutBlank = own(unwrap(cut(own(hex(HEX.nut, true)), own(cylinder(tap, HEX.nut)))) as Shape);
const tapped = own(compound([nutBlank, ...helixTooth(tap, rm + PLAY.bolt, UNC.pitch, edge, HEX.nut - edge, zBolt - zNut + UNC.pitch / 2)]) as Shape);
// Explode: the bolt and the nut move apart along the bolt, so the bolt turns by one turn for each pitch of that travel.
const [boltRise, nutRise] = [gap * 1.7, -gap * 0.35];
const bolt = own(translate(own(rotate(threaded, (360 * (boltRise - nutRise)) / UNC.pitch) as Shape), [0, 0, zBolt + boltRise]) as Shape);
const nut = own(translate(tapped, [0, 0, zNut + nutRise]) as Shape);
// Cutaway: a wedge about each axis, centred on +X. A fastener inside the wedge goes with the cut.
const sweep = (Math.max(cutaway, 1) * Math.PI) / 180;
const wedge = (z: number): Shape => own(rotate(own(lathe([[0, z], [400, z], [400, 400], [0, 400]], sweep)), -cutaway / 2) as Shape);
const open = (part: Shape, tools: Shape[]): Shape => (cutaway > 0 ? (unwrap(cutAll(part, tools)) as Shape) : (unwrap(clone(part)) as Shape));
const joint = [wedge(-100)];
const kept = (a: number): boolean => Math.min(a, 360 - a) > cutaway / 2 - 0.5;
const keptRing = (part: Shape): Shape[] => ring(part, rc).filter((_, i) => kept(angles[i]!));
const stack = { gasket: own(open(gasket, joint)), flange: [own(open(flange, joint)), ...flangeTeeth], pipe: [own(open(pipe, joint)), ...pipeTeeth], bolts: keptRing(bolt), nuts: keptRing(nut) };
const all = (parts: Shape[]): Shape => compound(ends.flatMap((end) => parts.map((p) => own(place(p, end))))) as Shape;
const along = own(rotate(wedge(-400), 90, { axis: [1, 0, 0] }) as Shape);
return {
tee: open(tee, [along, wedge(0)]),
flanges: all(stack.flange),
pipes: all(stack.pipe),
gaskets: all([stack.gasket]),
bolts: all(stack.bolts),
nuts: all(stack.nuts),
pounds,
catalogue: s.pounds,
};
}
const part = freeing(() => flangedTee());
console.log('Tee weight: ' + part.pounds.toFixed(1) + ' lb from the kernel volume. The catalogue has ' + part.catalogue + ' lb.');
export default [
color(part.tee, '#12b5b0'),
color(part.flanges, '#c3c9d1'),
color(part.pipes, '#f5f2ea'),
color(part.gaskets, '#ff5a1f'),
color(part.bolts, '#48515c'),
color(part.nuts, '#d3a956'),
];Functions used
clone compound cut cutAll cylinder extrude fuse intersect line loft measureVolume polygon revolve rotate translate unwrap wire color