O-Ring in a Piston Gland (cutaway)

An AS568 nitrile O-ring in a static piston gland, in cutaway. The ring sizes and the gland depth, width, clearance and corner radius are published figures. The kernel measures the rubber volume, and from it the stretch, the squeeze and the gland fill. The barrel, the piston body, the rod and the nut are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
ts
import { clone, compound, cut, cutAll, cylinder, extrude, face, intersect, line, loft, measureVolume, polygon, revolve, rotate, threePointArc, torus, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// AS568 O-ring in a static piston gland, in cutaway. The axis is Z and the units are millimetres.
// The ring sizes and the gland figures are published. The squeezed section keeps the rubber volume.
// The barrel, the piston body, the rod and the nut are a display model.
interface ORingParams {
dash?: 210 | 214 | 218 | 222; // AS568 size, all with the 0.139 in cord
cutaway?: number; // degrees of the barrel to cut away; the piston loses half of that and the ring a sixth
fitted?: boolean; // false takes the barrel off: the ring is round and stands proud of the piston
}
type P2 = [number, number]; // [r, z]
type Step = P2 | { via: P2; to: P2 }; // a line to a point, or an arc through via
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, as in the standard and the gland chart)
const INCH = 25.4;
const CORD = 0.139; // cross-section of the -2xx series
const NOMINAL_ID = { 210: 0.75, 214: 1, 218: 1.25, 222: 1.5 }; // the ring ID is 0.016 less; the bore is 0.25 more
const GLAND = { depth: 0.112, width: 0.19, clearance: 0.004, radius: 0.02, breakEdge: 0.005 }; // static male gland, middle of each range
const SQUEEZE = { min: 16, max: 23 }; // percent, from the same chart
const NUT = { thread: 8, minor: 6.647, pitch: 1.25, flats: 13, height: 6.8 }; // M8 coarse thread, right hand, and its hexagon nut
const WASHER = { inner: 8.4, outer: 16, height: 1.6 }; // M8 plain washer
// ---- display model
const PISTON = { length: 16, chamfer: 0.8 };
const BARREL = { wall: 4, above: 9, below: 9, flange: 12, flangeHeight: 6, bolt: 2.75, bolts: 6 };
const ROD = { radius: 6, length: 16, stickOut: 4 };
const PLAY = 0.08; // radial play between the rod thread and the nut thread
// A closed outline in the (r, z) half-plane, revolved about the axis.
const lathe = (steps: Step[], angle = 2 * Math.PI): Shape => {
const at = ([r, z]: P2): [number, number, number] => [r, 0, z];
const ends = steps.map((s) => (Array.isArray(s) ? s : s.to));
const edges = steps.map((s, i) => {
const from = ends[(i + steps.length - 1) % steps.length]!;
return own(Array.isArray(s) ? line(at(from), at(s)) : threePointArc(at(from), at(s.via), at(s.to)));
});
const profile = own(unwrap(face(own(unwrap(wire(edges))) as never)));
return unwrap(revolve(profile, { axis: [0, 0, 1], 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
};
const volume = (s: Shape): number => unwrap(measureVolume(s));
function seal({ dash = 214, cutaway = 160, fitted = true }: ORingParams = {}) {
const W = CORD * INCH;
const L = GLAND.depth * INCH;
const g = (GLAND.width * INCH) / 2;
const R = GLAND.radius * INCH;
const k = GLAND.breakEdge * INCH;
const ringId = (NOMINAL_ID[dash] - 0.016) * INCH;
const rb = ((NOMINAL_ID[dash] + 0.25) * INCH) / 2; // bore radius
const rc = rb - (GLAND.clearance * INCH) / 2; // piston radius
const rg = rb - L; // groove floor radius
const hp = PISTON.length / 2;
const c = PISTON.chamfer;
const rs = NUT.thread / 2;
const q = R * (1 - Math.SQRT1_2);
// Piston: chamfered ends, a groove with radiused floor corners and broken top edges.
const piston = own(lathe([
[rs, -hp], [rc - c, -hp], [rc, -hp + c], [rc, -g - k], [rc - k, -g], [rg + R, -g],
{ via: [rg + q, -g + q], to: [rg, -g + R] }, [rg, g - R], { via: [rg + q, g - q], to: [rg + R, g] },
[rc - k, g], [rc, g + k], [rc, hp - c], [rc - c, hp], [rs, hp],
]));
// The free ring is a torus. The kernel volume of it sets every later section.
const free = own(torus(ringId / 2 + W / 2, W / 2));
const rubber = volume(free);
// On the groove floor the ring is stretched, so the cord gets thinner.
let cord = W;
for (let i = 0; i < 8; i++) cord = 2 * Math.sqrt(rubber / (2 * Math.PI * Math.PI * (rg + cord / 2)));
// In the gland the cord is pressed flat between the floor and the bore. The section area stays the same.
const area = rubber / (2 * Math.PI * (rg + L / 2));
const flat = (area - (Math.PI * L * L) / 4) / L / 2; // half length of each flat
const pressed = (): Shape => lathe([
[rg, flat], { via: [rg + L / 2, flat + L / 2], to: [rb, flat] }, [rb, -flat], { via: [rg + L / 2, -flat - L / 2], to: [rg, -flat] },
]);
const ring = own(fitted ? pressed() : torus(rg + cord / 2, cord / 2));
// Gland fill: the ring volume against the empty space between the groove and the bore.
const gland = own(unwrap(cut(own(lathe([[rg, -g], [rb, -g], [rb, g], [rg, g]])), piston)) as Shape);
const stretch = ((2 * rg - ringId) / ringId) * 100;
const facts = { squeeze: ((cord - L) / cord) * 100, stretch, fill: (rubber / volume(gland)) * 100, rubber };
// Rod: a shoulder under the piston, a spigot through it, and the M8 thread from the piston face to the end.
const top = hp + WASHER.height + NUT.height;
const end = top + Math.floor(ROD.stickOut / NUT.pitch) * NUT.pitch;
const rm = NUT.minor / 2;
const edge = 0.42 * NUT.pitch; // a tooth ends this far from the end of its thread
const stem = own(lathe([
[0, -hp - ROD.length], [ROD.radius - 1, -hp - ROD.length], [ROD.radius, -hp - ROD.length + 1], [ROD.radius, -hp], [rs, -hp],
[rs, hp], [rm, hp], [rm, end], [rm - 0.5, end + 0.8], [0, end + 0.8],
]));
const rod = compound([stem, own(helixTooth(rm, rs, NUT.pitch, hp + edge + 0.2, end - edge, 0))]) as Shape;
const washer = lathe([[WASHER.inner / 2, hp], [WASHER.outer / 2, hp], [WASHER.outer / 2, hp + WASHER.height], [WASHER.inner / 2, hp + WASHER.height]]);
// Nut: a hexagon prism with both faces chamfered at 30 degrees.
const corner = NUT.flats / Math.sqrt(3) + 0.1;
const z0 = hp + WASHER.height;
const hex = Array.from({ length: 6 }, (_, i): [number, number, number] => [corner * Math.cos((i * Math.PI) / 3), corner * Math.sin((i * Math.PI) / 3), z0]);
const prism = own(unwrap(extrude(own(unwrap(polygon(hex))), [0, 0, NUT.height])) as Shape);
const drop = (corner - 0.46 * NUT.flats) * Math.tan(Math.PI / 6);
const tap = rs + PLAY; // the nut is bored to the major diameter and carries the mating tooth, half a pitch from the rod's
const cone = own(lathe([[tap, z0], [0.46 * NUT.flats, z0], [corner, z0 + drop], [corner, top - drop], [0.46 * NUT.flats, top], [tap, top]]));
const nut = compound([own(unwrap(intersect(prism, cone)) as Shape), own(helixTooth(tap, rm + PLAY, NUT.pitch, z0 + edge, top - edge, NUT.pitch / 2))]) as Shape;
// Barrel: a honed bore with a lead-in chamfer, on a bolted flange.
const zb = -hp - BARREL.below;
const zt = hp + BARREL.above;
const ro = rb + BARREL.wall;
const rf = rb + BARREL.flange;
const tube = own(lathe([
[rb, zb], [rf - 1, zb], [rf, zb + 1], [rf, zb + BARREL.flangeHeight - 1], [rf - 1, zb + BARREL.flangeHeight], [ro + 1.5, zb + BARREL.flangeHeight],
{ via: [ro + 0.44, zb + BARREL.flangeHeight + 0.44], to: [ro, zb + BARREL.flangeHeight + 1.5] },
[ro, zt - 0.6], [ro - 0.6, zt], [rb + 0.7, zt], [rb, zt - 2.6],
]));
const pcd = (ro + rf) / 2 + 0.3;
const holes = Array.from({ length: BARREL.bolts }, (_, i) => {
const a = ((i + 0.5) * 2 * Math.PI) / BARREL.bolts;
return own(cylinder(BARREL.bolt, BARREL.flangeHeight + 2, { at: [pcd * Math.cos(a), pcd * Math.sin(a), zb - 1] }));
});
const barrel = own(unwrap(cutAll(tube, holes)) as Shape);
// Cutaway: a wedge centred on +X comes off. The ring keeps most of its length, so its ends show the section.
const open = (s: Shape, degrees: number): Shape => {
if (degrees <= 0) return unwrap(clone(s)) as Shape;
const wedge = own(rotate(own(lathe([[0, zb - 9], [rf + 9, zb - 9], [rf + 9, zt + 9], [0, zt + 9]], (degrees * Math.PI) / 180)), -degrees / 2, { axis: [0, 0, 1] }) as Shape);
return unwrap(cut(s, wedge)) as Shape;
};
return { ring: open(ring, cutaway / 6), piston: open(piston, cutaway / 2), barrel: fitted ? [open(barrel, cutaway)] : [], rod, washer, nut, facts };
}
const part = freeing(() => seal());
console.log(
'Ring: ' + part.facts.rubber.toFixed(0) + ' mm3 of rubber by the kernel. Stretch ' + part.facts.stretch.toFixed(1) + ' %, squeeze ' + part.facts.squeeze.toFixed(1) +
' % (the chart gives ' + SQUEEZE.min + ' to ' + SQUEEZE.max + ' %), gland fill ' + part.facts.fill.toFixed(0) + ' %.',
);
export default [
color(part.ring, '#12b5b0'),
color(part.piston, '#d3a956'),
...part.barrel.map((s) => color(s, '#c3c9d1')),
color(part.rod, '#a9b1ba'),
color(part.washer, '#f2f4f7'),
color(part.nut, '#48515c'),
];Functions used
clone compound cut cutAll cylinder extrude face intersect line loft measureVolume polygon revolve rotate threePointArc torus unwrap wire color