Corner Bracket on Slotted Profiles

Two 20 x 20 slotted aluminium profiles joined by cast corner brackets with M5 screws and T-nuts. The upper bracket is exploded, the lower one is assembled. Each screw has a helical M5 x 0.8 thread that mates with the thread of its T-nut, and it turns one turn for each pitch as it backs out. The slot width, the slot depth, the bore, the web, the mass per metre, the bracket size and the thread are published figures. The kernel measures the mass per metre of the profile section. The cavity shape, the bracket walls and the T-nut body are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, compound, cutAll, cylinder, extrude, fuseAll, line, loft, measureVolume, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Cast corner brackets on two 20 x 20 slotted aluminium profiles, with M5 screws and T-nuts.
// The profile section figures, its mass per metre, the bracket size and the M5 thread are published figures.
// The cavity shape, the bracket walls and the T-nut body are a display model. Units are millimetres.
interface BracketParams {
explode?: number; // 0 = assembled, 1 = upper bracket and screws off. Each screw turns out of its T-nut, one turn for each pitch
brackets?: 1 | 2; // 2 adds an assembled bracket under the beam
beam?: number; // length of the horizontal profile
}
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 PROFILE = { size: 20, slot: 6.2, slotDepth: 6.1, bore: 5, web: 1.5 }; // 20 series, slot 6
const CATALOGUE_KG_M = 0.5;
const DENSITY = 2.7e-6; // aluminium, kilograms per cubic millimetre
const BRACKET = { leg: 20, width: 17 }; // 20 x 20 x 17 cast bracket
const SCREW = { major: 5, minor: 4.134, pitch: 0.8, length: 8, hole: 5.5 }; // M5 x 8, coarse thread, medium clearance hole
const HEAD = { diameter: 9.5, height: 2.75, socket: 3 }; // ISO 7380 button head
// ---- display model
const LIP = 1.8; // wall that closes the slot
const POCKET = 5.5; // half width of the cavity under the lip
const POST = 116;
const BEAM_TOP = 68;
const CAST = { wall: 3, web: 2, hole: 12, tab: { width: 4, length: 4, depth: 1.5 } };
const NUT = { length: 10, half: 5.2, thick: 3.2, flat: 3.6 };
const PLAY = 0.08; // radial play between the screw thread and the nut thread
const block = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Shape =>
own(box(x1 - x0, y1 - y0, z1 - z0, { at: [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2] }));
const prism = (pts: P3[], by: P3): Shape => own(unwrap(extrude(own(unwrap(polygon(pts))), by))) 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);
// The profile along +Z from z = 0. One outline holds the four slots and their cavities.
const profile = (length: number): Shape => {
const h = PROFILE.size / 2;
const s = PROFILE.slot / 2;
const floor = h - PROFILE.slotDepth;
const edge = (PROFILE.web / 2) * Math.SQRT2; // the cavity wall is parallel to the diagonal web
const side: P2[] = [
[h, -h], [h, -s], [h - LIP, -s], [h - LIP, -POCKET], [POCKET + edge, -POCKET], [floor, edge - floor],
[floor, floor - edge], [POCKET + edge, POCKET], [h - LIP, POCKET], [h - LIP, s], [h, s],
];
const outline = [0, 1, 2, 3].flatMap((k) => side.map(([x, y]): P3 => (k === 0 ? [x, y, 0] : k === 1 ? [-y, x, 0] : k === 2 ? [-x, -y, 0] : [y, -x, 0])));
return own(unwrap(cutAll(prism(outline, [0, 0, length]), [own(cylinder(PROFILE.bore / 2, length + 2, { at: [0, 0, -1] }))]))) as Shape;
};
function corner({ explode = 1, brackets = 2, beam = 80 }: BracketParams = {}) {
const h = PROFILE.size / 2;
const post = profile(POST);
const rail = own(translate(own(rotate(profile(beam), 90, { axis: [0, 1, 0] })), [h, 0, BEAM_TOP - h]) as Shape);
// Bracket above the beam: a leg on the post, a leg on the beam, two side walls, a tab in each slot.
const { wall, web, hole, tab } = CAST;
const w = BRACKET.width / 2;
const leg = BRACKET.leg;
const z = BEAM_TOP;
const walls = [-w, w - web].map((y) => prism([[h, y, z], [h + leg, y, z], [h + leg, y, z + wall], [h + wall, y, z + leg], [h, y, z + leg]], [0, web, 0]));
const tabs = [
block(h + leg - tab.length, h + leg, -tab.width / 2, tab.width / 2, z - tab.depth, z + 1),
block(h - tab.depth, h + 1, -tab.width / 2, tab.width / 2, z + leg - tab.length, z + leg),
];
const casting = own(unwrap(fuseAll([block(h, h + wall, -w, w, z, z + leg), block(h, h + leg, -w, w, z, z + wall), ...walls, ...tabs]))) as Shape;
const drill = SCREW.hole / 2;
const bracket = own(unwrap(cutAll(casting, [
own(cylinder(drill, wall + 2, { at: [h + hole, 0, z - 1] })),
own(cylinder(drill, wall + 2, { at: [h - 1, 0, z + hole], axis: [1, 0, 0] })),
]))) as Shape;
// Button head screw along Z, seat at z = 0: head with a hex socket, core and one helical tooth.
const dome: P2[] = [[0, HEAD.height], [HEAD.diameter / 2 - 1.6, HEAD.height], [HEAD.diameter / 2, 0.6], [HEAD.diameter / 2, 0], [0, 0]];
const body = own(unwrap(revolve(own(unwrap(polygon(dome.map(([r, t]): P3 => [r, 0, t])))), { axis: [0, 0, 1] }))) as Shape;
const hex = Array.from({ length: 6 }, (_, i): P3 => [(HEAD.socket / Math.sqrt(3)) * Math.cos((i * Math.PI) / 3), (HEAD.socket / Math.sqrt(3)) * Math.sin((i * Math.PI) / 3), HEAD.height - 1.8]);
const screw = own(compound([
own(unwrap(cutAll(body, [prism(hex, [0, 0, 3])]))),
own(cylinder(SCREW.minor / 2, SCREW.length, { at: [0, 0, -SCREW.length] })),
own(screwTooth(SCREW, -SCREW.length, 0)),
])) as Shape;
// T-nut for a slot that opens to +Z and runs along X, top against the lips at z = 0. Its thread mates with the screw.
const n = NUT;
const nutBlank = prism([[0, -n.half, 0], [0, n.half, 0], [0, n.half, -1.6], [0, n.flat, -n.thick], [0, -n.flat, -n.thick], [0, -n.half, -1.6]], [n.length, 0, 0]);
const tapped = own(unwrap(cutAll(nutBlank, [own(cylinder(SCREW.major / 2 + PLAY, n.thick + 2, { at: [n.length / 2, 0, -n.thick - 1] }))])));
const seat = wall + LIP; // from the screw seat down to the top of the nut
const nut = own(compound([tapped, own(translate(own(nutTooth(SCREW, -seat - n.thick, -seat)), [n.length / 2, 0, seat]))])) as Shape;
// Place the parts of one corner. On the post the same parts point to +X.
const up = (s: Shape, x: number, zz: number): Shape => own(translate(s, [x, 0, zz]) as Shape);
const out = (s: Shape, x: number, zz: number): Shape => own(translate(own(rotate(s, 90, { axis: [0, 1, 0] })), [x, 0, zz]) as Shape);
// Explode in the order of the work: the beam screw, then the post screw, then the bracket. The heads never cross.
// A screw that backs out by a distance turns by distance / pitch turns, so its thread stays in mesh with the nut.
const backed = (by: number): Shape => own(rotate(screw, (360 * by) / SCREW.pitch, { axis: [0, 0, 1] }) as Shape);
const kit = (lift: number) => {
const stage = (from: number, to: number): number => Math.min(1, Math.max(0, (lift - from) / (to - from)));
const first = 30 * stage(0, 0.35);
const second = 30 * stage(0.3, 0.65);
const b = 14 * stage(0.65, 1);
return {
brackets: [own(translate(bracket, [b, 0, b]) as Shape)],
screws: [up(backed(first), h + hole + b, z + wall + b + first), out(backed(second), h + wall + b + second, z + hole + b)],
nuts: [up(nut, h + hole - n.length / 2, z - LIP), out(nut, h - LIP, z + hole + n.length / 2)],
};
};
// The bracket under the beam stays assembled. It is the first one, turned half a turn about the axis of the beam.
const top = kit(Math.min(1, Math.max(0, explode)));
const fitted = kit(0);
const under = (s: Shape): Shape => own(rotate(s, 180, { axis: [1, 0, 0], at: [0, 0, BEAM_TOP - h] }) as Shape);
const all = (name: 'brackets' | 'screws' | 'nuts'): Shape => compound(brackets === 2 ? [...top[name], ...fitted[name].map(under)] : top[name]) as Shape;
const kgPerMetre = (unwrap(measureVolume(post)) / POST) * 1000 * DENSITY;
return { profiles: compound([post, rail]) as Shape, brackets: all('brackets'), screws: all('screws'), nuts: all('nuts'), kgPerMetre };
}
const part = freeing(() => corner());
console.log('Profile: ' + part.kgPerMetre.toFixed(3) + ' kg/m from the kernel volume. The catalogue has ' + CATALOGUE_KG_M + ' kg/m.');
export default [
color(part.profiles, '#c3c9d1'),
color(part.brackets, '#12b5b0'),
color(part.screws, '#48515c'),
color(part.nuts, '#d3a956'),
];Functions used
box compound cutAll cylinder extrude fuseAll line loft measureVolume polygon revolve rotate translate unwrap wire color