Wall-Mount Flanged Junction Box

A polycarbonate junction box with slotted wall flanges, a hinged lid with a gasket in its groove, M20 cable glands and a row of terminals on a top-hat rail. The M20 x 1.5 gland thread and its 24 mm hexagon, the 35 x 7.5 mm rail section and the M4 and M3 screw threads are published figures. Each thread is a true helix in its mating thread, and the captive lid screws are backed out of their posts when the lid is open. The kernel measures the mass of the base and the lid. The box, the hinge, the wall anchors, the terminals and the wiring are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, compound, cut, cutAll, cylinder, edgeFinder, extrude, fillet, fuseAll, line, loft, measureVolume, polygon, revolve, rotate, sphere, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Wall-mount junction box with slotted flanges, a hinged gasket lid, M20 cable glands and a terminal rail.
// It lies on its back: Z points away from the wall. Units are millimetres.
// The gland thread and hexagon, the rail section and the M4 and M3 screw threads are published figures.
// Each thread is a true helix in its mating thread: posts, rail pads, wall anchors, terminal clamps and gland nuts.
// The box, the hinge, the terminals and the wiring are a display model.
interface JunctionBoxParams {
open?: number; // lid angle in degrees. At 0 the lid screws are in the posts. An open lid has them backed out
glands?: number; // cable entries in the +X wall, 1 to 3
cables?: boolean; // false leaves the glands empty
}
type P2 = [number, number];
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
const GLAND = { thread: 20, minor: 18.376, pitch: 1.5, hex: 24, threadLength: 8, cable: [6, 12] }; // M20 x 1.5 polyamide gland
const RAIL = { width: 35, hat: 27, depth: 7.5, sheet: 1, slot: [6.2, 15] }; // top-hat rail 35 x 7.5, EN 60715
const M4 = { major: 4, minor: 3.242, head: 8, headHeight: 3.1, pitch: 0.7 }; // metric coarse thread, ISO 7045 pan head
const M3 = { major: 3, minor: 2.459, pitch: 0.5 }; // metric coarse thread of the terminal screws
const PC_DENSITY = 1.2e-3; // polycarbonate, grams per cubic millimetre
// ---- display model
const BOX = { x: 90, y: 130, height: 48, wall: 4.5, floor: 3, corner: 8 };
const LID = { height: 16, cap: 3 };
const SEAL = { width: 2.6, groove: 2.5, gasket: 1.5, tongue: 1 }; // gasket in a lid groove, tongue on the base rim
const POST = { radius: 6, inset: 8, depth: 10 }; // corner posts, tapped M4
const EAR = { reach: 16, width: 64, thick: 4, slot: [12, 5.2], slotAt: 20 }; // mounting flange on each short end
const HINGE = { out: 4, radius: 3.5, pin: 1.2, length: 9, at: 36 };
const BLOCK = { pitch: 6.2, entry: 7 }; // feed-through terminal
const CABLE = 9; // outside diameter, inside the clamping range of the gland
const GLAND_Z = 24;
const RAIL_X = -12;
const PLAY = 0.1; // radial play between a screw thread and its mating thread
const BACK_OUT = 8; // travel of a captive lid screw out of its post
const ANCHOR = { radius: 3.5, length: 13 }; // threaded wall anchor under each flange screw
const CLAMP = { from: 24, to: 27, screw: 2, slot: 0.6 }; // threaded clamp and slotted screw of a terminal, above the rail
const STOP = { screw: 6, hole: 6.5 }; // screw of an end stop
const CAP = { core: 9.2, crest: 10, from: 5, to: 10.6, bore: 11.1 }; // thread between the gland body and its cap nut
const brick = (l: number, w: number, h: number, x: number, y: number, z: number): Shape => box(l, w, h, { at: [x, y, z + h / 2] });
// Box with rounded vertical edges, centred on the Z axis, bottom at z.
const tub = (l: number, w: number, h: number, z: number, r: number): Shape =>
unwrap(fillet(own(brick(l, w, h, 0, 0, z)), edgeFinder().inDirection('Z'), r)) as Shape;
const ringOf = (l: number, w: number, t: number, h: number, z: number, r: number): Shape =>
unwrap(cut(own(tub(l, w, h, z, r)), own(tub(l - 2 * t, w - 2 * t, h + 2, z - 1, r - t)))) as Shape;
// 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;
};
// Turn a part that is built along +Z so that it points along +X, then move it.
const alongX = (s: Shape, at: P3): Shape => translate(own(rotate(s, 90, { axis: [0, 1, 0] })), at);
// A planar outline, extruded along a vector.
const prism = (pts: P3[], by: P3): Shape => unwrap(extrude(own(unwrap(polygon(pts))), by)) as Shape;
const hexagon = (flats: number, h: number): Shape => {
const r = flats / Math.sqrt(3);
return prism(Array.from({ length: 6 }, (_, i): P3 => [r * Math.cos((i * Math.PI) / 3), r * Math.sin((i * Math.PI) / 3), 0]), [0, 0, h]);
};
// A 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, tip < core is the thread in a hole. A right-hand thread.
// The tooth is a row of smooth lofts of 4 turns or less, end to end on one helix: a long loft is slow to mesh.
const FACETS = 12; // loft sections 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 span = to - from;
const pieces = Math.max(1, Math.ceil(span / pitch / 4));
const n = Math.max(2, Math.round((span / pieces / pitch) * FACETS)); // sections in each piece
const section = (z: number) => {
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((q, i) => own(line(q, pts[(i + 1) % 3]!))))));
};
const lofts = Array.from({ length: pieces }, (_, k) => own(unwrap(loft(Array.from({ length: n + 1 }, (_, j) => section(from + (span * (k + j / n)) / pieces)), { ruled: false }))));
return own(compound(lofts)) as Shape;
};
// A round wire through a list of points, with a ball at each bend.
const strand = (pts: P3[], r: number): Shape => {
const parts: Shape[] = [];
for (let i = 1; i < pts.length; i++) {
const a = pts[i - 1]!;
const b = pts[i]!;
const d: P3 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
parts.push(own(cylinder(r, Math.hypot(d[0], d[1], d[2]), { at: a, axis: d })));
if (i < pts.length - 1) parts.push(own(sphere(r, { at: b })));
}
return unwrap(fuseAll(parts)) as Shape;
};
const F4 = 0.42 * M4.pitch; // half width of an M4 tooth at its root
// Pan-head screw, head top at z = 0: a cross recess and one helical tooth on the threaded length at the end.
// A shorter thread leaves a waisted shank, as a captive screw has.
const panScrew = (length: number, threaded = length): Shape => {
const k = M4.headHeight;
const rc = M4.minor / 2;
const end = -k - length;
const blank = own(lathe([[0, 0], [M4.head / 2 - 1.2, 0], [M4.head / 2, -1.2], [M4.head / 2, -k], [rc, -k], [rc, end + 0.3], [rc - 0.3, end], [0, end]]));
const head = own(unwrap(cutAll(blank, [own(brick(4.8, 0.9, 2, 0, 0, -1.7)), own(brick(0.9, 4.8, 2, 0, 0, -1.7))])) as Shape);
return compound([head, helixTooth(rc, M4.major / 2, M4.pitch, end + 0.3 + F4, end + threaded - F4, 0)]) as Shape;
};
// The thread of a tapped M4 hole from z = from to z = to, for a screw with its head top at z = headTop. Half a pitch from the screw.
const tapped4 = (from: number, to: number, headTop: number): Shape => helixTooth(M4.major / 2 + PLAY, M4.minor / 2 + PLAY, M4.pitch, from + F4, to - F4, headTop + M4.pitch / 2);
const volume = (s: Shape): number => unwrap(measureVolume(s));
function junctionBox({ open = 105, glands = 3, cables = true }: JunctionBoxParams = {}) {
const { x: ox, y: oy, height: h, wall, corner } = BOX;
const mid = wall / 2; // gasket line, from the outer face
const px = ox / 2 - POST.inset;
const py = oy / 2 - POST.inset;
const posts: P2[] = [[px, py], [-px, py], [-px, -py], [px, -py]];
const count = Math.max(1, Math.min(3, Math.round(glands)));
const entries = Array.from({ length: count }, (_, i) => (i - (count - 1) / 2) * 36);
const pivot: P3 = [-ox / 2 - HINGE.out, 0, h];
const railTop = BOX.floor + 3 + RAIL.depth;
const slotsAt = [-37.5, -12.5, 12.5, 37.5]; // 25 mm pitch
// Base: tray, flanges with gussets, corner posts, rail pads, hinge knuckles and the rim tongue.
const knuckle = (side: number): Shape => own(unwrap(fuseAll([
own(cylinder(HINGE.radius, HINGE.length, { at: [pivot[0], -HINGE.length / 2, h], axis: [0, 1, 0] })),
own(brick(HINGE.out + 1, HINGE.length, HINGE.radius + 3, pivot[0] + (HINGE.out + 1) / 2, 0, side > 0 ? h : h - HINGE.radius - 3)),
])) as Shape);
const ears = [1, -1].flatMap((s) => [
own(unwrap(fillet(own(brick(EAR.width, EAR.reach + 2, EAR.thick, 0, s * (oy / 2 + EAR.reach / 2 - 1), 0)), edgeFinder().inDirection('Z'), 5)) as Shape),
...[-29.5, 0, 29.5].map((x) => own(prism([[x - 1.5, s * (oy / 2 - 1), EAR.thick], [x - 1.5, s * (oy / 2 - 1), 22], [x - 1.5, s * (oy / 2 + EAR.reach - 2), EAR.thick]], [3, 0, 0]))),
]);
const shellBase = own(unwrap(cut(own(tub(ox, oy, h, 0, corner)), own(tub(ox - 2 * wall, oy - 2 * wall, h, BOX.floor, corner - wall)))) as Shape);
const solidBase = own(unwrap(fuseAll([
shellBase,
...ears,
own(ringOf(ox - 2 * mid + SEAL.width - 0.6, oy - 2 * mid + SEAL.width - 0.6, SEAL.width - 0.6, SEAL.tongue + 0.5, h - 0.5, corner - mid + SEAL.width / 2)),
...posts.map(([x, y]) => own(cylinder(POST.radius, h - 1, { at: [x, y, 1] }))),
...[slotsAt[0]!, slotsAt[3]!].map((y) => own(cylinder(5, 4, { at: [RAIL_X, y, BOX.floor - 1] }))),
...[1, -1].map((s) => own(translate(knuckle(-1), [0, s * HINGE.at - HINGE.length / 2, 0]))),
])) as Shape);
const moulded = own(unwrap(cutAll(solidBase, [
...posts.map(([x, y]) => own(cylinder(M4.major / 2 + PLAY, POST.depth + 1, { at: [x, y, h - POST.depth] }))),
...entries.map((y) => own(cylinder(GLAND.thread / 2 + 0.2, wall + 2, { at: [ox / 2 - wall - 1, y, GLAND_Z], axis: [1, 0, 0] }))),
...[1, -1].flatMap((s) => [1, -1].map((t) => own(translate(own(tub(EAR.slot[0]!, EAR.slot[1]!, EAR.thick + 2, -1, EAR.slot[1]! / 2 - 0.01)), [t * EAR.slotAt, s * (oy / 2 + EAR.reach / 2 + 0.5), 0])))),
...[slotsAt[0]!, slotsAt[3]!].map((y) => own(cylinder(M4.major / 2 + PLAY, 5, { at: [RAIL_X, y, BOX.floor - 1] }))),
own(cylinder(HINGE.pin + 0.1, oy, { at: [pivot[0], -oy / 2, h], axis: [0, 1, 0] })),
])) as Shape);
// Lid: shell with soft top edges, posts, counterbores, the gasket groove and two hinge knuckles.
const lidBlank = own(tub(ox, oy, LID.height + 4, h - 4, corner));
const soft = own(unwrap(fillet(lidBlank, edgeFinder().not((f) => f.inDirection('Z')), 2)) as Shape);
const seat = h + LID.height - M4.headHeight - 0.3;
// Threads of the posts and of the rail pads, in phase with their screws.
const lidTop = seat + M4.headHeight;
const railHead = railTop - RAIL.depth + RAIL.sheet + M4.headHeight;
const postThread = tapped4(h - POST.depth + 2, h, lidTop);
const padThread = tapped4(BOX.floor - 0.8, railTop - RAIL.depth, railHead);
const base = compound([moulded, ...posts.map(([x, y]) => own(translate(postThread, [x, y, 0]))), ...[slotsAt[0]!, slotsAt[3]!].map((y) => own(translate(padThread, [RAIL_X, y, 0])))]) as Shape;
const lidShell = own(unwrap(cutAll(soft, [own(brick(ox + 2, oy + 2, 5, 0, 0, h - 5)), own(tub(ox - 2 * wall, oy - 2 * wall, LID.height - LID.cap + 1, h - 1, corner - wall))])) as Shape);
const lidSolid = own(unwrap(fuseAll([
lidShell,
...posts.map(([x, y]) => own(cylinder(POST.radius, LID.height - 1, { at: [x, y, h] }))),
...[1, -1].map((s) => own(translate(knuckle(1), [0, s * HINGE.at + HINGE.length / 2, 0]))),
])) as Shape);
const lidWhole = own(unwrap(cutAll(lidSolid, [
own(ringOf(ox - 2 * mid + SEAL.width, oy - 2 * mid + SEAL.width, SEAL.width, SEAL.groove + 1, h - 1, corner - mid + SEAL.width / 2)),
...posts.flatMap(([x, y]) => [own(cylinder(2.3, LID.height + 2, { at: [x, y, h - 1] })), own(cylinder(M4.head / 2 + 0.5, LID.height, { at: [x, y, seat] }))]),
own(tub(ox * 0.5, oy * 0.45, 1, h + LID.height - 0.6, 3)),
own(cylinder(HINGE.pin + 0.1, oy, { at: [pivot[0], -oy / 2, h], axis: [0, 1, 0] })),
])) as Shape);
const grams = (volume(moulded) + volume(lidWhole)) * PC_DENSITY;
const swing = (s: Shape): Shape => rotate(s, -open, { axis: [0, 1, 0], at: pivot });
const lid = swing(lidWhole);
const gasketFlat = own(ringOf(ox - 2 * mid + SEAL.width - 0.2, oy - 2 * mid + SEAL.width - 0.2, SEAL.width - 0.2, SEAL.gasket, h + SEAL.groove - SEAL.gasket, corner - mid + SEAL.width / 2));
const gasket = swing(gasketFlat);
const dark: Shape[] = [];
const steel: Shape[] = [];
const part = (list: Shape[], s: Shape): void => { list.push(own(s)); };
// Screws: four captive in the lid, four through the flange slots into wall anchors, two in the rail. Two hinge pins.
// Before the lid can open, each lid screw turns out of its post: one turn for each pitch of travel.
const backOut = open > 0 ? BACK_OUT : 0;
const lidScrew = own(rotate(own(panScrew(20, 9)), (360 * backOut) / M4.pitch));
const wallScrew = own(panScrew(16, 12));
const railScrew = own(panScrew(4));
posts.forEach(([x, y]) => part(steel, swing(own(translate(lidScrew, [x, y, lidTop + backOut])))));
const wallTop = EAR.thick + 0.8 + M4.headHeight;
const sleeve = own(unwrap(cut(own(cylinder(ANCHOR.radius, ANCHOR.length, { at: [0, 0, -ANCHOR.length] })), own(cylinder(M4.major / 2 + PLAY, ANCHOR.length + 2, { at: [0, 0, -ANCHOR.length - 1] })))) as Shape);
const anchor = own(compound([sleeve, tapped4(-ANCHOR.length + 1.4, 0, wallTop)]) as Shape);
for (const s of [1, -1]) for (const t of [1, -1]) {
const at: P3 = [t * EAR.slotAt, s * (oy / 2 + EAR.reach / 2 + 0.5), EAR.thick];
part(steel, unwrap(cut(own(cylinder(5.5, 0.8, { at })), own(cylinder(2.2, 2, { at: [at[0], at[1], at[2] - 0.5] })))) as Shape);
part(steel, translate(wallScrew, [at[0], at[1], wallTop]));
part(dark, translate(anchor, [at[0], at[1], 0]));
}
for (const s of [1, -1]) part(steel, cylinder(HINGE.pin, 2 * HINGE.length + 2, { at: [pivot[0], s * HINGE.at - HINGE.length - 1, h], axis: [0, 1, 0] }));
// Top-hat rail on two pads, with its slots.
const r = RAIL;
const z0 = railTop - r.depth;
const half = r.hat / 2;
const hat: P2[] = [
[-r.width / 2, r.depth - r.sheet], [-half, r.depth - r.sheet], [-half, 0], [half, 0], [half, r.depth - r.sheet], [r.width / 2, r.depth - r.sheet],
[r.width / 2, r.depth], [half - r.sheet, r.depth], [half - r.sheet, r.sheet], [r.sheet - half, r.sheet], [r.sheet - half, r.depth], [-r.width / 2, r.depth],
];
const railBlank = own(prism(hat.map(([x, z]): P3 => [RAIL_X + x, -45, z0 + z]), [0, 90, 0]));
const slot = own(tub(r.slot[0]!, r.slot[1]!, 3, z0 - 1, r.slot[0]! / 2 - 0.01));
const rail = unwrap(cutAll(railBlank, slotsAt.map((y) => own(translate(slot, [RAIL_X, y, 0]))))) as Shape;
for (const y of [slotsAt[0]!, slotsAt[3]!]) part(steel, translate(railScrew, [RAIL_X, y, railHead]));
// Terminals: one master block with two clamp wells and two wire entries, copied along the rail.
// Each well has a threaded steel clamp with a slotted M3 screw in it.
const outline: P2[] = [[-22, 0], [22, 0], [22, 12], [17, 17], [17, 26], [11, 26], [11, 30], [3, 30], [3, 27], [-3, 27], [-3, 30], [-11, 30], [-11, 26], [-17, 26], [-17, 17], [-22, 12]];
const blockBlank = own(prism(outline.map(([x, z]): P3 => [RAIL_X + x, -BLOCK.pitch / 2, railTop + z]), [0, BLOCK.pitch, 0]));
const block = own(unwrap(cutAll(blockBlank, [1, -1].flatMap((s) => [
own(cylinder(1.9, 7, { at: [RAIL_X + s * 7, 0, railTop + 24] })),
own(cylinder(1.7, 7, { at: [RAIL_X + s * 15, 0, railTop + BLOCK.entry], axis: [s, 0, 0] })),
]))) as Shape);
const [c3, m3, f3] = [M3.minor / 2, M3.major / 2, 0.42 * M3.pitch];
const inM3 = (from: number, to: number): Shape => helixTooth(m3 + PLAY, c3 + PLAY, M3.pitch, from + f3, to - f3, M3.pitch / 2);
const onM3 = (from: number, to: number): Shape => helixTooth(c3, m3, M3.pitch, from + f3, to - f3, 0);
const k = CLAMP;
const tube = own(unwrap(cut(own(cylinder(1.9, k.to - k.from, { at: [0, 0, k.from] })), own(cylinder(m3 + PLAY, k.to - k.from + 2, { at: [0, 0, k.from - 1] })))) as Shape);
const stub = own(unwrap(cut(own(cylinder(c3, k.screw, { at: [0, 0, k.to - k.screw] })), own(brick(4, 0.6, 1, 0, 0, k.to - k.slot)))) as Shape);
const clamp = own(translate(own(compound([tube, inM3(k.to - k.screw, k.to), stub, onM3(k.to - k.screw, k.to - k.slot)]) as Shape), [0, 0, railTop]));
const ways = count * 3;
const wayY = (i: number): number => (i - (ways - 1) / 2) * BLOCK.pitch;
const blocks: Shape[][] = [[], [], []];
const cores: Shape[][] = [[], [], []];
for (let i = 0; i < ways; i++) {
blocks[i % 3]!.push(own(translate(block, [0, wayY(i), 0])));
for (const s of [1, -1]) part(steel, translate(clamp, [RAIL_X + s * 7, wayY(i), 0]));
}
// End stops: a slotted M3 screw in a tapped hole of each stop.
const drilled = own(unwrap(cut(own(brick(34, 8, 22, 0, 0, 0)), own(cylinder(m3 + PLAY, STOP.hole + 1, { at: [0, 0, 22 - STOP.hole] })))) as Shape);
const stop = own(compound([drilled, inM3(22 - STOP.hole + 0.3, 22)]) as Shape);
const slotted = own(unwrap(cut(own(lathe([[0, 22 - STOP.screw], [c3 - 0.2, 22 - STOP.screw], [c3, 22.2 - STOP.screw], [c3, 22], [2, 22], [2, 23.2], [0, 23.2]])), own(brick(5, 0.6, 1, 0, 0, 22.6)))) as Shape);
const stopScrew = own(compound([slotted, onM3(22.2 - STOP.screw, 22)]) as Shape);
for (const s of [1, -1]) {
const y = s * (wayY(ways - 1) + BLOCK.pitch / 2 + 4);
part(dark, translate(stop, [RAIL_X, y, railTop]));
part(steel, translate(stopScrew, [RAIL_X, y, railTop]));
}
// Glands: thread through the wall, lock nut inside, body, cap nut and dome outside. Then the cable and its three cores.
// One master on Z from the inner end of the thread. The lock nut and the cap nut have the mating threads.
const g = GLAND;
const [gc, gm, gf, out] = [g.minor / 2, g.thread / 2, 0.42 * g.pitch, g.threadLength];
const lockNut = own(unwrap(cut(own(hexagon(g.hex, 3.5)), own(cylinder(gm + PLAY, 6, { at: [0, 0, -1] })))) as Shape);
const capNut = own(unwrap(cut(own(translate(own(hexagon(g.hex, 9)), [0, 0, out + 6.6])), own(cylinder(CAP.crest + PLAY, CAP.bore - 5.6, { at: [0, 0, out + 5.6] })))) as Shape);
const gland = own(compound([
own(cylinder(gc, out)), helixTooth(gc, gm, g.pitch, 0.1 + gf, out - gf, 0),
lockNut, helixTooth(gm + PLAY, gc + PLAY, g.pitch, gf, 3.5 - gf, g.pitch / 2),
own(translate(own(hexagon(g.hex, 5)), [0, 0, out])),
own(cylinder(CAP.core, CAP.to - CAP.from, { at: [0, 0, out + CAP.from] })), helixTooth(CAP.core, CAP.crest, g.pitch, out + CAP.from + gf, out + CAP.to - gf, 0),
capNut, helixTooth(CAP.crest + PLAY, CAP.core + PLAY, g.pitch, out + 6.6 + gf, out + CAP.bore - gf, g.pitch / 2),
own(lathe([[0, out + 15.6], [11, out + 15.6], [10.2, out + 19], [7.6, out + 22.5], [CABLE / 2 + 1.2, out + 23.6], [0, out + 23.6]])),
]) as Shape);
entries.forEach((y, n) => {
part(dark, alongX(gland, [ox / 2 - out, y, GLAND_Z]));
if (!cables) return;
const end = ox / 2 - g.threadLength;
part(dark, cylinder(CABLE / 2, 30, { at: [ox / 2 + 23.6, y, GLAND_Z], axis: [1, 0, 0] }));
part(dark, cylinder(CABLE / 2, 6, { at: [end, y, GLAND_Z], axis: [-1, 0, 0] }));
for (let k = 0; k < 3; k++) {
const from: P3 = [end - 6, y + (k - 1) * 2.1, GLAND_Z + (k === 1 ? 2.4 : -1.2)]; // three cores in a triangle
const to: P3 = [RAIL_X + 22, wayY(n * 3 + k), railTop + BLOCK.entry];
cores[k]!.push(own(strand([from, [from[0] - 2, from[1], from[2]], [to[0] + 3, to[1], to[2]], [to[0] - 7, to[1], to[2]]], 1)));
}
});
const tints = ['#48515c', '#e6e9ee', '#f5f2ea', '#12b5b0', '#d3a956', '#ff5a1f', '#12b5b0', '#d3a956'];
const groups = [dark, steel, ...blocks, ...cores].map((list, i) => ({ list, tint: tints[i]! })).filter((group) => group.list.length > 0);
return { base, lid, gasket, rail, grams, groups: groups.map((group) => ({ shape: compound(group.list) as Shape, tint: group.tint })) };
}
const built = freeing(() => junctionBox());
console.log('Polycarbonate base and lid: ' + built.grams.toFixed(0) + ' g from the kernel volumes.');
export default [
color(built.base, '#c3c9d1'),
color(built.lid, '#c3c9d1'),
color(built.gasket, '#12b5b0'),
color(built.rail, '#e6e9ee'),
...built.groups.map((group) => color(group.shape, group.tint)),
];Functions used
box compound cut cutAll cylinder edgeFinder extrude fillet fuseAll line loft measureVolume polygon revolve rotate sphere translate unwrap wire color