Louvered Enclosure Cover

The louvered cover of an equipment enclosure, from 20 gauge steel, with its screws, a name plate and the enclosure behind it. Each louver is a cut on three sides with the flap formed out along the fourth side, so the flat blank keeps all its material. The gauge and the screw threads are published figures. The M4 screws and the cable glands have true helical threads in tapped holes. The kernel unfolds the cover to the flat blank and measures its mass. The size, the louvers, the enclosure and the hardware are a display model. The DXF button downloads the flat blank.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, clone, compound, cutAll, cylinder, line, loft, measureVolume, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { addPolygonCutout, author, flatPatternToPolylines, louver, toDXF, unfold } from 'brepjs-sheetmetal';
import { color, present } from 'brepjs/playground';
// Louvered cover of an equipment enclosure, from 20 gauge steel. Each louver is a cut on three sides:
// a press forms the flap out along the fourth side, so no material leaves the blank.
// The gauge, the density and the screw threads are published figures. The size, the louvers, the enclosure and the hardware are a display model.
interface PanelParams {
fold?: number; // 0 to 1: how far the four edge flanges are folded. Below 1 the example shows only the cover
rows?: number; // rows of louvers, 1 to 9
height?: number; // formed height of each louver in millimetres
}
type P2 = [number, number];
type P3 = [number, number, number];
type Shape = ReturnType<typeof box>;
type Part = Extract<ReturnType<typeof author>, { ok: true }>['value'];
// 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 T = 0.912; // 20 gauge steel sheet, 0.0359 inch
const STEEL = 7.85e-3; // grams per cubic millimetre
const M4 = { d: 4, minor: 3.242, pitch: 0.7, head: 8, k: 3.1, length: 10 }; // pan head screw with a cross recess, metric coarse thread, right hand
const M16 = { d: 16, minor: 14.376, pitch: 1.5 }; // metric thread of a cable gland
// ---- display model
const RULE = { innerRadius: 1, kFactor: 0.44 }; // air bend
const COVER = { width: 240, height: 320, flange: 12, notch: 6 }; // the flanges stop short of each corner
const LOUVER = { length: 90, width: 10, pitch: 22, columns: [65, 175], top: 76 }; // top: from the top edge to the first row
const SCREWS: P2[] = [[10, 10], [230, 10], [10, 160], [230, 160], [10, 310], [230, 310]];
const BOX = { depth: 90, rim: 20 };
const PLATE = { width: 70, height: 22, y: 20 }; // the name plate
const TAPPED = 12; // depth of the tapped holes in the rim
const PLAY = 0.08; // radial play between a screw thread and its tapped hole
const made = (r: ReturnType<typeof author>): Part => {
const p = unwrap(r);
if (p.solid) own(p.solid);
return p;
};
const ngon = (x: number, y: number, r: number, n: number): P2[] =>
Array.from({ length: n }, (_, i): P2 => [x + r * Math.cos((i * 2 * Math.PI) / n), y + r * Math.sin((i * 2 * Math.PI) / n)]);
// The cover is made face down: X is across, Y is from the top edge down, and the flanges fold up. The louvers go out of the face and open toward +Y.
function cover(rows: number, height: number, angle: number): Part {
const flange = (id: string, side: 'xmin' | 'xmax' | 'ymin' | 'ymax', edge: number) =>
({ id, side, length: COVER.flange, angleDeg: angle, rule: RULE, offset: COVER.notch, width: edge - 2 * COVER.notch });
let p = made(author({ thickness: T, base: { length: COVER.width, width: COVER.height }, flanges: [
flange('left', 'xmin', COVER.height), flange('right', 'xmax', COVER.height), flange('top', 'ymin', COVER.width), flange('bottom', 'ymax', COVER.width),
] }));
for (let row = 0; row < rows; row++) {
for (const x of LOUVER.columns) p = made(louver(p, { region: 'base', x, y: LOUVER.top + row * LOUVER.pitch, length: LOUVER.length, width: LOUVER.width, height }));
}
for (const [x, y] of SCREWS) p = made(addPolygonCutout(p, 'base', ngon(x, y, 2.4, 16)));
return p;
}
const block = (x0: number, y0: number, z0: number, x1: number, y1: number, z1: number): Shape => own(translate(own(box(x1 - x0, y1 - y0, z1 - z0)), [x0, y0, z0])) as Shape;
const lathe = (profile: P2[]): Shape => own(unwrap(revolve(own(unwrap(polygon(profile.map(([r, z]): P3 => [r, 0, z])))))) as Shape);
// One helical thread tooth about +Z, from z = from to z = to. Its crest passes the +X side at z = ref.
// 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.
// tip > core is the thread of a screw on a core of that radius. tip < core is the thread in a bore.
const SECTIONS = 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 start = from + half, span = to - from - 2 * half, pieces = Math.ceil(span / (4 * pitch));
const n = Math.max(2, Math.round((span / pieces / pitch) * SECTIONS)); // sections in each piece
const section = (z: number) => {
const a = (2 * Math.PI * (z - ref)) / pitch;
const pts = [[root, -half], [crest, 0], [root, half]].map(([r, dz]): P3 => [r! * Math.cos(a), r! * Math.sin(a), z + dz!]);
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(start + (span * (k + j / n)) / pieces)), { ruled: false }))));
return own(compound(lofts)) as Shape;
};
// The thread of a screw between two heights, and the mating thread of a nut or a tapped hole, half a pitch out of phase.
type Thread = { d: number; minor: number; pitch: number };
const screwTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.minor / 2, m.d / 2, m.pitch, z0, z1, 0);
const nutTooth = (m: Thread, z0: number, z1: number): Shape => helixTooth(m.d / 2 + PLAY, m.minor / 2 + PLAY, m.pitch, z0, z1, m.pitch / 2);
// The enclosure and the small parts, in the frame of the cover: the face is on Z = 0, and the back is on Z = T.
function hardware() {
const { width: w, height: h } = COVER;
const outward = (s: Shape): Shape => own(rotate(s, 180, { axis: [1, 0, 0] })) as Shape; // a turned part that points out of the face
// The enclosure: a box with a rim for the screws. The cover lies on the rim, and its flanges go around the box.
const holes = SCREWS.map(([x, y]) => own(cylinder(M4.d / 2 + PLAY, TAPPED, { at: [x, y, T] })));
const glandAt = [70, 170], mid = T + BOX.depth / 2;
const entries = glandAt.map((x) => own(cylinder(M16.d / 2 + PLAY, BOX.rim + 2, { at: [x, h - BOX.rim - 1, mid], axis: [0, 1, 0] })));
const body = own(unwrap(cutAll(block(0, 0, T, w, h, T + BOX.depth), [block(BOX.rim, BOX.rim, T - 1, w - BOX.rim, h - BOX.rim, T + BOX.depth - 2), ...holes, ...entries]))) as Shape;
// M4 x 10 pan head screws with a cross recess. Each has one helical tooth, and each tapped hole in the rim has the mating tooth.
const head = lathe([[0, 0], [M4.head / 2, 0], [M4.head / 2, 1.4], [2.4, M4.k], [0, M4.k]]);
const cross = [0, 90].map((turn) => own(rotate(block(-2.3, -0.4, 1.9, 2.3, 0.4, 3.5), turn)));
const screw = own(compound([outward(own(unwrap(cutAll(head, cross))) as Shape), own(cylinder(M4.minor / 2, M4.length)), screwTooth(M4, 0, M4.length)])) as Shape;
const tapped = nutTooth(M4, T, T + TAPPED);
const screws = SCREWS.map(([x, y]) => own(translate(screw, [x, y, 0])) as Shape);
const threads = SCREWS.map(([x, y]) => own(translate(tapped, [x, y, 0])) as Shape);
// The name plate, with a rivet at each end.
const px = w / 2 - PLATE.width / 2;
const plate = block(px, PLATE.y, -0.8, px + PLATE.width, PLATE.y + PLATE.height, 0);
const rivet = outward(lathe([[0, 0], [1.8, 0], [1.2, 0.8], [0, 0.8]]));
const rivets = [px + 5, px + PLATE.width - 5].map((x) => own(translate(rivet, [x, PLATE.y + PLATE.height / 2, -0.8])) as Shape);
// Two cable glands under the box: a hex body with an M16 thread on each side, a dome nut, and a piece of cable.
// The entry thread turns into a tapped hole of the box, and the dome nut has the mating thread of the body.
const hex = (r: number, z0: number, z1: number): Shape =>
own(unwrap(cutAll(own(cylinder(r * 1.3, z1 - z0, { at: [0, 0, z0] })), [0, 60, 120].flatMap((turn) => [-1, 1].map((side) => own(rotate(block(-2 * r, side > 0 ? r : -3 * r, z0 - 1, 2 * r, side > 0 ? 3 * r : -r, z1 + 1), turn))))))) as Shape;
const bore = M16.d / 2 + PLAY;
const gland = [
hex(11, 0, 5), lathe([[bore, 5], [10.5, 5], [10.5, 13], [8.5, 17], [0, 17], [0, 13], [bore, 13]]), nutTooth(M16, 5, 13),
own(cylinder(M16.minor / 2, 8, { at: [0, 0, -8] })), screwTooth(M16, -8, 0), own(cylinder(M16.minor / 2, 7.5, { at: [0, 0, 5] })), screwTooth(M16, 5, 12.5),
];
const entryTooth = nutTooth(M16, -BOX.rim, 0);
const cable = own(cylinder(4, 28, { at: [0, 0, 17] }));
const down = (s: Shape, x: number): Shape => own(translate(own(rotate(s, -90, { axis: [1, 0, 0] })), [x, h, T + BOX.depth / 2])) as Shape;
const glands = glandAt.flatMap((x) => gland.map((s) => down(s, x)));
const cables = glandAt.map((x) => down(cable, x));
return { body: compound([body, ...threads, ...glandAt.map((x) => down(entryTooth, x))]) as Shape, bright: compound([...screws, ...rivets, ...glands]) as Shape, plate: unwrap(clone(plate)) as Shape, cables: compound(cables) as Shape };
}
function panel({ fold = 1, rows = 9, height = 6 }: PanelParams = {}) {
const n = Math.min(9, Math.max(1, Math.round(rows)));
const part = cover(n, height, 90 * Math.min(1, Math.max(0.02, fold)));
// The report and the flat blank come from the full cover, also when the view is part folded.
const full = fold < 1 ? cover(n, height, 90) : part;
const flat = unwrap(unfold(full));
[flat.pattern.outline, ...flat.pattern.holes, ...flat.pattern.formCuts, ...flat.pattern.formMarkers, ...flat.pattern.formHinges, ...flat.pattern.bendLines.map((l) => l.line)].forEach((handle) => own(handle));
const count = n * LOUVER.columns.length;
const info = {
dxf: unwrap(toDXF(flat.pattern)), overlay2d: flatPatternToPolylines(flat.pattern),
size: flat.report.totalFlatSize, allowance: flat.report.bends[0]?.allowance ?? 0, bends: flat.report.bends.length,
grams: unwrap(measureVolume(full.solid as Shape)) * STEEL, count, vent: (count * LOUVER.length * height) / 100,
};
const sheet = unwrap(clone(part.solid as Shape)) as Shape;
return fold < 1 ? { sheet, ...info } : { sheet, ...hardware(), ...info };
}
// Try panel({ fold: 0.4 }) to see the flanges part folded, or panel({ rows: 5, height: 9 }).
const model = freeing(() => panel());
console.log(
model.count + ' louvers with a free area of ' + model.vent.toFixed(0) + ' cm2. ' + model.bends + ' bends, each with an allowance of ' + model.allowance.toFixed(2) + ' mm. ' +
'Flat blank: ' + model.size.map((v) => v.toFixed(1)).join(' x ') + ' mm. Mass of the cover: ' + model.grams.toFixed(0) + ' g from the kernel volume.',
);
// Stand the cover up, with its face toward the camera. The louvers open down.
const show = (s: Shape, css: string) => {
const up = rotate(s, -90, { axis: [1, 0, 0] });
const turned = rotate(up, 90, { axis: [0, 0, 1] });
s.delete();
up.delete();
return color(turned, css);
};
// The DXF button downloads the flat blank: the outline, the bend lines, the holes, and the three cuts of each louver.
export default present(
[show(model.sheet, '#12b5b0'), ...('body' in model ? [show(model.body, '#48515c'), show(model.bright, '#e9ebee'), show(model.plate, '#f5f2ea'), show(model.cables, '#2b2f36')] : [])],
{ dxf: model.dxf, overlay2d: model.overlay2d },
);Functions used
box clone compound cutAll cylinder line loft measureVolume polygon revolve rotate translate unwrap wire addPolygonCutout author flatPatternToPolylines louver toDXF unfold color present