Rubber-Lined Pipe P-Clamp

A rubber-lined P-clip that holds a 20 mm tube on a mounting bar, with its hex screw, plain washers and nut. The bar ends on the screw axis, so the helical thread of the screw and the mating thread of the nut show in section. The band widths with their hole and screw sizes are datasheet figures, and the threads are metric coarse. The band thickness, the liner section, the bends, the screw length 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, compound, cut, cutAll, cylinder, extrude, face, intersect, line, loft, polygon, revolve, rotate, threePointArc, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Rubber-lined P-clip that holds a tube on a mounting bar, with its screw, washers and nut.
// The tube is along Y, the bar top is at z = 0, and the units are millimetres.
// The band widths, the hole sizes and the screw sizes are datasheet figures. The rest is a display model.
interface ClipParams {
tube?: number; // tube outside diameter, 8 to 40
band?: 12 | 15 | 20; // band width
open?: number; // 0..1 springs the clip open. The screw is then out of the nut, turned by one turn for each pitch
}
type P2 = [number, number]; // [x, z]
type P3 = [number, number, number];
type Shape = ReturnType<typeof cylinder>;
interface Node { p: P2; mid?: P2 } // mid: the edge that ends at p is an arc through mid
// 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 (rubber-lined P-clip datasheet: band width, hole diameter, metric screw)
const BANDS = {
12: { hole: 5.3, screw: 5 },
15: { hole: 6.4, screw: 6 },
20: { hole: 8.4, screw: 8 },
};
// ---- display model
const SHEET = 1; // band thickness
const LINER = { wall: 1.6, side: 1.2, lip: 0.5, wrap: 3 }; // rubber channel around the band
const NECK = 2; // radius of the reverse bend where the two legs meet
const SPRING = 26; // degrees that the top leg lifts at open = 1
const SCREWS = {
5: { major: 5, minor: 4.134, pitch: 0.8, length: 16, flats: 8, head: 3.5, nut: 4.7, washer: 10, plate: 1 },
6: { major: 6, minor: 4.917, pitch: 1, length: 20, flats: 10, head: 4, nut: 5.2, washer: 12, plate: 1.6 },
8: { major: 8, minor: 6.647, pitch: 1.25, length: 20, flats: 13, head: 5.3, nut: 6.8, washer: 16, plate: 1.6 },
}; // metric coarse hex screw with the thread to the head, nut and plain washer
const PLAY = 0.08; // radial play between the screw thread and the nut thread
const BAR = 5; // mounting bar thickness
const TUBE = { wall: 1.5, length: 52 };
const d2r = Math.PI / 180;
const polar = ([cx, cz]: P2, r: number, deg: number): P2 => [cx + r * Math.cos(deg * d2r), cz + r * Math.sin(deg * d2r)];
const turn = ([x, z]: P2, [cx, cz]: P2, deg: number): P2 => {
const c = Math.cos(deg * d2r);
const s = Math.sin(deg * d2r);
return [cx + (x - cx) * c - (z - cz) * s, cz + (x - cx) * s + (z - cz) * c];
};
// A closed outline of lines and arcs in the XZ plane at y, as a face.
const outline = (nodes: Node[], y: number) => {
const at = ([x, z]: P2): P3 => [x, y, z];
const edges = nodes.map((n, i) => {
const from = nodes[(i + nodes.length - 1) % nodes.length]!.p;
return own(n.mid ? threePointArc(at(from), at(n.mid), at(n.p)) : line(at(from), at(n.p)));
});
return own(unwrap(face(own(unwrap(wire(edges))) as never)));
};
// A closed profile in the (r, z) half-plane, revolved about Z.
const lathe = (pts: P2[]): Shape => {
const profile = own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z]))));
return unwrap(revolve(profile, { axis: [0, 0, 1] })) 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 of a screw on a core of that radius. tip < core is the thread in a bore.
// The loft is smooth: each flank is one helical face.
const FACETS = 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 root = tip > core ? core / SLACK : core * SLACK;
const crest = tip > core ? tip : tip / SLACK;
const half = 0.42 * pitch;
const n = Math.max(2, Math.round(((to - from) / pitch) * FACETS));
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): 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 unwrap(loft(sections, { ruled: false })) as Shape;
};
// The thread of a screw between two heights, and the mating thread of a nut or a tapped hole. The two are half a pitch apart.
const screwTooth = (m: { major: number; minor: number; pitch: number }, z0: number, z1: number): Shape =>
helixTooth(m.minor / 2, m.major / 2, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, 0);
const nutTooth = (m: { major: number; minor: number; pitch: number }, z0: number, z1: number): Shape =>
helixTooth(m.major / 2 + PLAY, m.minor / 2 + PLAY, m.pitch, z0 + 0.42 * m.pitch, z1 - 0.42 * m.pitch, m.pitch / 2);
const hex = (flats: number, height: number, z: number): Shape => {
const rc = 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), z]))));
const bevel = own(lathe([[0, z], [0.84 * rc, z], [rc, z + 0.1 * rc], [rc, z + height - 0.1 * rc], [0.84 * rc, z + height], [0, z + height]]));
return unwrap(intersect(own(unwrap(extrude(flat, height)) as Shape), bevel)) as Shape;
};
function pClip({ tube = 20, band = 15, open = 0 }: ClipParams = {}) {
const spec = BANDS[band];
const screw = SCREWS[spec.screw as 5 | 6 | 8];
const t = SHEET;
const lift = Math.min(Math.max(open, 0), 1);
const spring = SPRING * lift;
// ---- band: one strip. Bottom leg, loop, reverse bend, top leg. The centre line is offset by half a sheet each way.
const inner = tube / 2 + LINER.wall; // inside radius of the steel loop
const mean = inner + t / 2;
const centre: P2 = [0, t / 2 + mean];
const neckZ = 1.5 * t + NECK;
const neckX = Math.sqrt((mean + NECK) ** 2 - (centre[1] - neckZ) ** 2);
const neck: P2 = [neckX, neckZ];
const meet = Math.atan2(neckZ - centre[1], neckX) / d2r; // loop angle where the reverse bend starts (below zero)
const holeX = neckX + screw.washer / 2 + 1.5;
const end = holeX + band / 2;
const loopEnd = meet + spring - 360;
const side = (s: number): Node[] => {
const up = (p: P2): P2 => turn(p, centre, spring); // the reverse bend and the top leg lift about the loop centre
const loop = [1, 2, 3].map((i): Node => {
const a0 = -90 + ((loopEnd + 90) * (i - 1)) / 3;
const a1 = -90 + ((loopEnd + 90) * i) / 3;
return { p: polar(centre, mean + s, a1), mid: polar(centre, mean + s, (a0 + a1) / 2) };
});
const bend: Node = { p: up([neckX, 1.5 * t + s]), mid: up(polar(neck, NECK - s, (meet + 180 + 270) / 2)) };
return [{ p: [end, t / 2 - s] }, { p: [0, t / 2 - s] }, ...loop, bend, { p: up([end, 1.5 * t + s]) }];
};
const out = side(t / 2);
const back = side(-t / 2);
const returning = back.map((_, i): Node => ({ p: back[back.length - 1 - i]!.p, mid: back[back.length - i]?.mid }));
const strip = own(unwrap(extrude(outline([...out, ...returning], -band / 2), [0, band, 0])) as Shape);
// Screw hole and round end, once for each leg. The top set turns with the top leg.
const trim = (z0: number, z1: number): Shape[] => {
const block = own(box(band, band + 2, z1 - z0, { at: [holeX + band / 2, 0, (z0 + z1) / 2] }));
return [own(cylinder(spec.hole / 2, z1 - z0, { at: [holeX, 0, z0] })), own(unwrap(cut(block, own(cylinder(band / 2, z1 - z0, { at: [holeX, 0, z0] })))) as Shape)];
};
const lifted = (part: Shape): Shape => own(rotate(part, -spring, { axis: [0, 1, 0], at: [0, 0, centre[1]] }) as Shape);
const clip = unwrap(cutAll(strip, [...trim(-1, t), ...trim(t, 2 * t + 1).map(lifted)])) as Shape;
// ---- rubber liner: a channel around the band, revolved along the loop
const h = band / 2;
const o = inner + t;
const clear = Math.acos(o / (o + LINER.lip)) / d2r; // the lip starts where it clears the bar
const start = -90 - clear;
const channel: P2[] = [
[-h - LINER.side, inner - LINER.wall], [h + LINER.side, inner - LINER.wall], [h + LINER.side, o + LINER.lip], [h - LINER.wrap, o + LINER.lip],
[h - LINER.wrap, o], [h, o], [h, inner], [-h, inner], [-h, o], [-h + LINER.wrap, o], [-h + LINER.wrap, o + LINER.lip], [-h - LINER.side, o + LINER.lip],
]; // [y, radius]
const section = own(unwrap(polygon(channel.map(([y, r]): P3 => {
const [x, z] = polar(centre, r, start);
return [x, y, z];
}))));
const liner = unwrap(revolve(section, { axis: [0, 1, 0], at: [0, 0, centre[1]], angle: (start - loopEnd) * d2r })) as Shape;
// ---- tube and mounting bar, in section at the screw
const pipe = unwrap(cut(
own(cylinder(tube / 2, TUBE.length, { at: [0, -TUBE.length / 2, centre[1]], axis: [0, 1, 0] })),
own(cylinder(tube / 2 - TUBE.wall, TUBE.length, { at: [0, -TUBE.length / 2, centre[1]], axis: [0, 1, 0] })),
)) as Shape;
const x0 = -inner - t - 8;
const barBlank = own(box(holeX - x0, band + 24, BAR, { at: [(holeX + x0) / 2, 0, -BAR / 2] })); // ends on the screw axis, so the thread shows
const bar = unwrap(cut(barBlank, own(cylinder(spec.hole / 2, BAR + 2, { at: [holeX, 0, -BAR - 1] })))) as Shape;
// ---- hex screw from the top, plain washers, nut under the bar. One helical tooth on the screw, its mate in the nut.
const top = 2 * t + screw.plate;
const tip = top - screw.length;
const nutTop = -BAR - screw.plate;
const ring = (z: number): Shape => own(lathe([[spec.hole / 2, z], [screw.washer / 2, z], [screw.washer / 2, z + screw.plate], [spec.hole / 2, z + screw.plate]]));
const out3 = lift > 0 ? tube + 30 + 20 * lift : 0; // the screw comes out when the clip is open
const put = (part: Shape, dz: number): Shape => translate(part, [holeX, 0, dz]) as Shape;
const whole = own(compound([own(hex(screw.flats, screw.head, top)), own(cylinder(screw.minor / 2, screw.length, { at: [0, 0, tip] })), own(screwTooth(screw, tip, top))]) as Shape);
// The screw and the nut part by 4/3 of out3. The screw turns by that distance / pitch turns.
const bolt = put(own(rotate(whole, (360 * (4 / 3) * out3) / screw.pitch, { axis: [0, 0, 1] }) as Shape), out3);
const tapped = own(unwrap(cut(own(hex(screw.flats, screw.nut, nutTop - screw.nut)), own(cylinder(screw.major / 2 + PLAY, screw.nut + 2, { at: [0, 0, nutTop - screw.nut - 1] })))) as Shape);
const nut = put(own(compound([tapped, own(nutTooth(screw, nutTop - screw.nut, nutTop))]) as Shape), -out3 / 3);
const washers = [put(ring(2 * t), out3 * 0.9), put(ring(nutTop), -out3 / 5)];
return { clip, liner, pipe, bar, bolt, nut, washers };
}
const part = freeing(() => pClip());
export default [
color(part.clip, '#c3c9d1'),
color(part.liner, '#12b5b0'),
color(part.pipe, '#ff5a1f'),
color(part.bar, '#8a939e'),
color(part.bolt, '#d3a956'),
color(part.nut, '#d3a956'),
...part.washers.map((w) => color(w, '#f5f2ea')),
];Functions used
box compound cut cutAll cylinder extrude face intersect line loft polygon revolve rotate threePointArc translate unwrap wire color