Conduit Snap Clip

A snap clip that holds steel EMT conduit on a wall strip, with three wires in the conduit and the screw and wall plug shown in section. The wood screw has a helical thread with a 1.8 mm pitch that runs out on its cone point, and the plug has the mating thread that the screw forms in it. The outside diameter, the wall and the weight of the three trade sizes are published figures. The kernel measures the weight of the conduit for each metre. The clip, the screw, the plug, the wires and the wall strip 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, cone, cut, cutAll, cylinder, extrude, fuseAll, line, loft, measureVolume, polygon, revolve, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Snap clip that holds steel EMT conduit on a wall strip, with its screw and wall plug in section. Units are mm.
// The conduit runs along Y. Its diameter, wall and weight for each trade size are published figures.
// The screw is a 4 x 30 wood screw with a helical thread, and the plug has the thread that the screw forms in it.
// The clip, the screw section, the plug, the wires and the wall strip are a display model.
interface ClipParams {
size?: '1/2' | '3/4' | '1'; // EMT trade size
lift?: number; // mm that the conduit is lifted out of the clip (0 = snapped in, at least the rest position on the jaws)
section?: boolean; // false leaves the wall strip and the plug whole
}
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 (steel EMT: outside diameter and wall in inches, weight in kg for each 30.5 m)
const EMT = {
'1/2': { od: 0.706, wall: 0.042, kg: 13.6 },
'3/4': { od: 0.922, wall: 0.049, kg: 20.9 },
'1': { od: 1.163, wall: 0.057, kg: 30.4 },
};
const STEEL = 7.85e-3; // grams per cubic millimetre
// ---- display model
const CLIP = { thick: 2, width: 16, foot: 3, jaw: 38 }; // jaw = half angle of the opening, in degrees
const SCREW = { head: 4, shank: 2, core: 1.4, pitch: 1.8, length: 30, plain: 9, point: 4, flank: 0.25 }; // radii. flank = half width of the tooth at its root
const PLAY = 0.08; // radial play between the screw thread and the thread in the plug
const PLUG = { radius: 3, length: 25 };
const WIRE = { jacket: 1.65, copper: 1, past: 5 };
const TUBE = 56; // length of the conduit piece
const STRIP = { half: 24, width: 30, thick: 34 };
const block = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Shape =>
box(x1 - x0, y1 - y0, z1 - z0, { at: [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2] });
// A cylinder along Y, centred on y = 0.
const bar = (radius: number, length: number, x: number, z: number): Shape => cylinder(radius, length, { at: [x, -length / 2, z], axis: [0, 1, 0] });
// A closed profile in the (r, z) half-plane, revolved about the Z axis.
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.
// root and crest give the radius at a height, so the thread can run out on a cone point. half is the half width at the root.
// root gets the height of the section and the offset of its corner.
// outward makes the thread of a screw on its core. If not, it 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 = (root: (z: number, dz: number) => number, crest: (z: number) => number, pitch: number, half: number, from: number, to: number, ref: number, outward: boolean): Shape => {
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 base = (dz: number): P3 => at(outward ? root(z, dz) / SLACK : root(z, dz) * SLACK, dz);
const pts = [base(-half), at(outward ? crest(z) : crest(z) / SLACK, 0), base(half)];
return own(unwrap(wire(pts.map((p, i) => own(line(p, pts[(i + 1) % 3]!))))));
});
return unwrap(loft(sections, { ruled: false })) as Shape;
};
function conduitClip({ size = '1/2', lift: asked = 0, section = true }: ClipParams = {}) {
const emt = EMT[size];
const r = (emt.od * 25.4) / 2;
const wall = emt.wall * 25.4;
const zc = r + CLIP.thick + CLIP.foot; // conduit axis above the wall
const w = CLIP.width;
// Clip: a C ring on a foot, with a rolled lip on each jaw and a countersunk screw hole in the seat.
const jaw = (CLIP.jaw * Math.PI) / 180;
const lip = 0.8 * CLIP.thick;
const reach = 3 * r;
const lift = asked > 0 ? Math.max(asked, 2 * (r + lip) * Math.cos(jaw)) : 0; // the rigid jaws do not let the conduit stop lower
const mouth = own(unwrap(polygon([[0, -w, zc], [-reach * Math.sin(jaw), -w, zc + reach * Math.cos(jaw)], [reach * Math.sin(jaw), -w, zc + reach * Math.cos(jaw)]])));
const seat = zc - r;
const headTop = seat - 0.4;
const ring = own(unwrap(cutAll(own(unwrap(fuseAll([own(bar(r + CLIP.thick, w, 0, zc)), own(block(-0.8 * r, 0.8 * r, -w / 2, w / 2, 0, zc))])) as Shape), [
own(bar(r, w + 2, 0, zc)),
own(unwrap(extrude(mouth, [0, 2 * w, 0])) as Shape),
])) as Shape);
const lips = [-1, 1].map((side) => own(bar(lip, w, side * (r + lip) * Math.sin(jaw), zc + (r + lip) * Math.cos(jaw))));
const drill = [
own(cylinder(SCREW.shank, 20, { at: [0, 0, -5] })),
own(cone(SCREW.shank, SCREW.head, SCREW.head - SCREW.shank, { at: [0, 0, headTop - (SCREW.head - SCREW.shank)] })),
own(cylinder(SCREW.head, 3, { at: [0, 0, headTop] })),
];
const clip = unwrap(cutAll(own(unwrap(fuseAll([ring, ...lips])) as Shape), drill)) as Shape;
// Screw: countersunk head with a cross recess, plain shank, core with a cone point, and one helical tooth that runs out on the point.
const sc = SCREW;
const tip = headTop - sc.length;
const start = headTop - sc.plain;
const taper = (z: number): number => Math.min(1, (z - tip) / sc.point);
const turned = own(lathe([[0, headTop], [sc.head, headTop], [sc.shank, headTop - (sc.head - sc.shank)], [sc.shank, start], [sc.core, start], [sc.core, tip + sc.point], [0, tip]]));
// Two lofts that meet where the point starts: one on the parallel core, one on the cone.
const knee = tip + sc.point + sc.flank;
// A section that lies across the start of the point has its two root corners on the parallel core, so that it does not cut the corner.
const across = (z: number): boolean => Math.abs(z - tip - sc.point) < sc.flank;
const tooth = [[knee, start - sc.flank], [tip + 0.8 + sc.flank, knee]].map(([from, to]) =>
own(helixTooth((z, dz) => sc.core * (across(z) ? 1 : taper(z + dz)), (z) => sc.shank * taper(z), sc.pitch, sc.flank, from!, to!, 0, true)));
const screw = compound([
own(unwrap(cutAll(turned, [own(block(-2.6, 2.6, -0.5, 0.5, headTop - 1.3, headTop + 1)), own(block(-0.5, 0.5, -2.6, 2.6, headTop - 1.3, headTop + 1))])) as Shape),
...tooth,
]) as Shape;
// Wall strip and plug, cut on the plane of the screw axis when section is true.
// The plug has the formed thread: the mating tooth, half a pitch from the tooth of the screw.
const half = section ? [own(block(0, 60, -40, 40, -60, 0))] : [];
const bore = sc.shank + PLAY;
const wide = 0.42 * sc.pitch;
const formed = own(helixTooth(() => bore, () => sc.core + PLAY, sc.pitch, wide, tip + sc.point + wide, start - wide, sc.pitch / 2, false));
const sleeve = own(lathe([[bore, 0], [PLUG.radius, 0], [PLUG.radius, -PLUG.length], [bore, -PLUG.length]]));
const plug = compound([own(unwrap(cutAll(sleeve, half)) as Shape), section ? own(unwrap(cutAll(formed, half)) as Shape) : formed]) as Shape;
const strip = unwrap(cutAll(own(block(-STRIP.half, STRIP.half, -STRIP.width / 2, STRIP.width / 2, -STRIP.thick, 0)), [own(cylinder(PLUG.radius, PLUG.length + 4, { at: [0, 0, -PLUG.length - 4] })), ...half])) as Shape;
// Conduit: a tube of the published section. The kernel volume gives its weight for each metre.
const tube = own(unwrap(cut(own(bar(r, TUBE, 0, zc)), own(bar(r - wall, TUBE + 2, 0, zc)))) as Shape);
const kgPerMetre = (unwrap(measureVolume(tube)) / TUBE) * STEEL;
// Three wires that lie in the bottom of the conduit.
const ri = r - wall;
const low = -Math.sqrt((ri - WIRE.jacket) ** 2 - WIRE.jacket ** 2);
const spots: P2[] = [[-WIRE.jacket, low], [WIRE.jacket, low], [0, low + WIRE.jacket * Math.sqrt(3)]];
const up = (s: Shape): Shape => (lift > 0 ? (translate(own(s), [0, 0, lift]) as Shape) : s);
const wires = spots.map(([x, z]) => {
const jacket = own(bar(WIRE.jacket, TUBE + 2 * WIRE.past, x, zc + z));
return up(unwrap(cut(jacket, own(bar(WIRE.copper, TUBE + 20, x, zc + z)))) as Shape);
});
const copper = spots.map(([x, z]) => up((bar(WIRE.copper, TUBE + 2 * WIRE.past + 3, x, zc + z))));
return { clip, screw, plug, strip, conduit: lift > 0 ? (translate(tube, [0, 0, lift]) as Shape) : (unwrap(clone(tube)) as Shape), wires, copper: compound(copper.map(own)) as Shape, kgPerMetre, catalogue: emt.kg / 30.5 };
}
const part = freeing(() => conduitClip());
console.log('Conduit: ' + part.kgPerMetre.toFixed(3) + ' kg for each metre, from the kernel volume. The published weight gives ' + part.catalogue.toFixed(3) + ' kg.');
export default [
color(part.strip, '#f5f2ea'),
color(part.plug, '#d3a956'),
color(part.screw, '#c3c9d1'),
color(part.clip, '#12b5b0'),
color(part.conduit, '#c3c9d1'),
color(part.wires[0]!, '#ff5a1f'),
color(part.wires[1]!, '#48515c'),
color(part.wires[2]!, '#f5f2ea'),
color(part.copper, '#c9783c'),
];Functions used
box clone compound cone cut cutAll cylinder extrude fuseAll line loft measureVolume polygon revolve translate unwrap wire color