Skip to content

Vented Louvre Instrument Case ​

Vented Louvre Instrument Case, rendered in the brepjs playground
Mechanical · 288 lines▶ Run it in the playground

An instrument case for a small linear power supply: a sliding cover with formed louvres, perforated side walls and a 40 mm fan behind a honeycomb grille. Inside are a toroidal transformer, two can capacitors and a regulator board. The fan frame and its 32 mm hole pitch, the M3 and M5 screw threads and heads and the open-area formula for round holes on 60 degree centres are published figures. Each screw has a helical thread in a mating nut, standoff or tapped hole. The kernel measures the open area of the side vents and prints it beside the formula. The case and the parts in it 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, edgeFinder, extrude, fillet, fuseAll, line, loft, measureVolume, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// Vented instrument case for a small linear power supply. Z is up, units are millimetres.
// The cover has formed louvres, the side walls are perforated and a fan sits behind a honeycomb grille.
// The fan frame, its hole pitch, the screw threads and heads and the open-area formula are published figures.
// The case and the parts in it are a display model.
interface CaseParams {
  slide?: number; // 0 = closed, 1 = cover pulled back by the full case length
  louvres?: number; // louvres in each of the two rows, 3 to 9
  holeDiameter?: number; // side perforation, mm. The pitch stays the same.
}

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 FAN = { frame: 40, depth: 10, holePitch: 32 }; // 40 mm axial fan
const M3 = { major: 3, minor: 2.459, pitch: 0.5, head: 5.6, headHeight: 2.4, nutFlats: 5.5, nutHeight: 2.4 }; // ISO 7045 pan head, ISO 4032 nut
const M5 = { major: 5, minor: 4.134, pitch: 0.8, flats: 8, headHeight: 3.5, nutHeight: 4.7, length: 35, thread: 16 }; // ISO 4014 hex bolt
const SET = { length: 4, slot: 0.4, slotDepth: 0.9 }; // ISO 4766 slotted set screw, M3 x 4
const STAGGERED_ROUND = 90.69; // open area in percent = 90.69 x D x D / (C x C), round holes on 60 degree centres
const GRID = 2.54;

// ---- display model
const CASE = { length: 140, width: 100, height: 50, sheet: 2, corner: 3 };
const COVER = { sheet: 1.6, lip: 8, slack: 0.3 };
const LOUVRE = { length: 34, radius: 6, sheet: 1.2, pitch: 14, rowAt: 23 };
const PERF = { pitch: 6, rows: 4, columns: 13, z: 16 };
const HONEY = { flats: 6.4, pitch: 7.6, radius: 17.5 };
const CORE = { inner: 9, outer: 22, height: 24, round: 4, x: 16, y: -22 }; // toroidal transformer
const FAN_Z = 24; // fan axis above the bottom of the case
const PLAY = 0.08; // radial play between a screw thread and its nut thread

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;
// 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]);
};
// 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 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; // sections of the loft in each turn
const SLACK = 0.998; // keeps the tooth a hair clear of its core or its bore
const TURNS = 4; // turns in one loft
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 pieces = Math.ceil((to - from) / (TURNS * pitch));
  const n = Math.max(2, Math.round(((to - from) / 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((p, i) => own(line(p, pts[(i + 1) % 3]!))))));
  };
  const lofts = Array.from({ length: pieces }, (_, k) =>
    own(unwrap(loft(Array.from({ length: n + 1 }, (_, j) => section(from + ((to - from) * (k + j / n)) / pieces)), { ruled: false }))));
  return compound(lofts) 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);
// M3 pan-head screw with a cross recess, head top at z = 0, thread to the head.
const panScrew = (length: number): Shape => {
  const k = M3.headHeight;
  const head = own(lathe([[0, 0], [M3.head / 2 - 0.9, 0], [M3.head / 2, -0.9], [M3.head / 2, -k], [0, -k]]));
  return compound([
    own(unwrap(cutAll(head, [own(brick(3.4, 0.7, 1.4, 0, 0, -1.2)), own(brick(0.7, 3.4, 1.4, 0, 0, -1.2))])) as Shape),
    own(cylinder(M3.minor / 2, length, { at: [0, 0, -k - length] })),
    own(screwTooth(M3, -k - length, -k)),
  ]) as Shape;
};
const volume = (s: Shape): number => unwrap(measureVolume(s));

function ventedCase({ slide = 0.55, louvres = 9, holeDiameter = 4 }: CaseParams = {}) {
  const { length: ol, width: ow, height: h, sheet } = CASE;
  const wallX = ol / 2;
  const inner = wallX - sheet;
  const fanHoles: P2[] = [1, -1].flatMap((a) => [1, -1].map((b): P2 => [a * FAN.holePitch / 2, b * FAN.holePitch / 2]));

  // Base tray with the honeycomb grille and the fan screw holes in the +X wall.
  const tray = own(unwrap(cut(own(tub(ol, ow, h, 0, CASE.corner)), own(tub(ol - 2 * sheet, ow - 2 * sheet, h, sheet, CASE.corner - sheet)))) as Shape);
  const cell = own(hexagon(HONEY.flats, sheet + 2));
  const rowStep = HONEY.pitch * Math.sin(Math.PI / 3);
  const cells: Shape[] = [];
  for (let j = -3; j <= 3; j++) for (let i = -4; i <= 4; i++) {
    const y = i * HONEY.pitch + (j % 2 ? HONEY.pitch / 2 : 0);
    if (Math.hypot(y, j * rowStep) < HONEY.radius) cells.push(own(alongX(cell, [inner - 1, y, FAN_Z + j * rowStep])));
  }
  const grilled = own(unwrap(cutAll(tray, [...cells, ...fanHoles.map(([y, z]) => own(cylinder(1.75, sheet + 2, { at: [inner - 1, y, FAN_Z + z], axis: [1, 0, 0] }))),
    own(cylinder(2.75, sheet + 2, { at: [CORE.x, CORE.y, -1] })),
  ])) as Shape);

  // Side perforation: round holes on 60 degree centres through both long walls.
  const holes: Shape[] = [];
  for (let j = 0; j < PERF.rows; j++) for (let i = 0; i < PERF.columns; i++) {
    const x = (i - (PERF.columns - 1) / 2) * PERF.pitch + (j % 2 ? PERF.pitch / 2 : 0);
    holes.push(own(cylinder(holeDiameter / 2, ow + 2, { at: [x, -ow / 2 - 1, PERF.z + j * PERF.pitch * Math.sin(Math.PI / 3)], axis: [0, 1, 0] })));
  }
  const base = unwrap(cutAll(grilled, holes)) as Shape;
  const holeArea = (volume(grilled) - volume(base)) / (2 * sheet) / holes.length;
  const openMeasured = (100 * holeArea) / (PERF.pitch * PERF.pitch * Math.sin(Math.PI / 3));
  const openFormula = (STAGGERED_ROUND * holeDiameter * holeDiameter) / (PERF.pitch * PERF.pitch);
  const feet = [1, -1].flatMap((a) => [1, -1].map((b) => own(cylinder(7, 5, { at: [a * (wallX - 16), b * (ow / 2 - 16), -5] }))));

  // Cover: a plate with two side lips. Each louvre is a slot with a quarter-round hood that opens toward +X.
  const lv = LOUVRE;
  const top = h + COVER.sheet;
  const quarter = (y0: number, y1: number, r0: number, r1: number): Shape =>
    unwrap(revolve(own(unwrap(polygon([[0, y0, top + r0], [0, y1, top + r0], [0, y1, top + r1], [0, y0, top + r1]]))), { axis: [0, -1, 0], at: [0, 0, top], angle: Math.PI / 2 })) as Shape;
  const hood = own(unwrap(fuseAll([
    own(quarter(-lv.length / 2, lv.length / 2, lv.radius - lv.sheet, lv.radius)),
    own(quarter(-lv.length / 2 - lv.sheet, -lv.length / 2, 0, lv.radius)),
    own(quarter(lv.length / 2, lv.length / 2 + lv.sheet, 0, lv.radius)),
  ])) as Shape);
  const count = Math.max(3, Math.min(9, Math.round(louvres)));
  const spots: P2[] = [1, -1].flatMap((side) => Array.from({ length: count }, (_, i): P2 => [(i - (count - 1) / 2) * lv.pitch + 2, side * lv.rowAt]));
  const coverW = ow + 2 * (COVER.slack + COVER.sheet);
  const plate = own(unwrap(fuseAll([
    own(brick(ol, coverW, COVER.sheet, 0, 0, h)),
    ...[1, -1].map((side) => own(brick(ol, COVER.sheet, COVER.lip, 0, side * (coverW - COVER.sheet) / 2, top - COVER.lip))),
  ])) as Shape);
  const slotted = own(unwrap(cutAll(plate, spots.map(([x, y]) => own(brick(lv.radius - lv.sheet, lv.length, COVER.sheet + 2, x - (lv.radius - lv.sheet) / 2, y, h - 1))))) as Shape);
  const coverWhole = own(unwrap(fuseAll([slotted, ...spots.map(([x, y]) => own(translate(hood, [x, y, 0])))])) as Shape);
  const cover = translate(coverWhole, [-slide * ol, 0, 0]);

  const dark: Shape[] = [];
  const steel: Shape[] = [];
  const brass: Shape[] = [];
  const orange: Shape[] = [];
  const white: Shape[] = [];
  const part = (list: Shape[], s: Shape): void => { list.push(own(s)); };

  // Fan: a frame with a round duct, a motor plate on three struts and a seven-blade rotor.
  const f = FAN;
  const fx = inner - f.depth;
  const frameCut = own(unwrap(cutAll(own(brick(f.depth, f.frame, f.frame, fx + f.depth / 2, 0, FAN_Z - f.frame / 2)), [
    own(cylinder(18.5, f.depth + 2, { at: [fx - 1, 0, FAN_Z], axis: [1, 0, 0] })),
    ...fanHoles.map(([y, z]) => own(cylinder(1.75, f.depth + 2, { at: [fx - 1, y, FAN_Z + z], axis: [1, 0, 0] }))),
  ])) as Shape);
  const spin = (s: Shape, deg: number): Shape => rotate(s, deg, { axis: [1, 0, 0], at: [0, 0, FAN_Z] });
  part(dark, unwrap(fuseAll([
    frameCut,
    own(cylinder(9, 2, { at: [fx, 0, FAN_Z], axis: [1, 0, 0] })),
    ...[20, 140, 260].map((deg) => own(spin(own(brick(2, 2.4, 12, fx + 1, 0, FAN_Z + 8)), deg))),
  ])) as Shape);
  const blade = own(rotate(own(brick(1, 8, 9.4, fx + 5.6, 0, FAN_Z + 8.5)), 35, { axis: [0, 0, 1], at: [fx + 5.6, 0, FAN_Z] }));
  part(orange, unwrap(fuseAll([
    own(cylinder(9, 7.4, { at: [fx + 2, 0, FAN_Z], axis: [1, 0, 0] })),
    ...Array.from({ length: 7 }, (_, i) => own(spin(blade, (i * 360) / 7))),
  ])) as Shape);
  // Each fan screw goes through the wall and the frame into a nut. The nut is made in the frame of the screw.
  const k = M3.headHeight;
  const fanScrew = own(panScrew(16));
  const nutZ = -k - sheet - f.depth - M3.nutHeight;
  const m3Nut = own(compound([
    own(unwrap(cut(own(translate(own(hexagon(M3.nutFlats, M3.nutHeight)), [0, 0, nutZ])), own(cylinder(M3.major / 2 + PLAY, M3.nutHeight + 2, { at: [0, 0, nutZ - 1] })))) as Shape),
    own(nutTooth(M3, nutZ, nutZ + M3.nutHeight)),
  ]) as Shape);
  fanHoles.forEach(([y, z]) => [fanScrew, m3Nut].forEach((s) => part(steel, alongX(s, [wallX + k, y, FAN_Z + z]))));

  // Toroidal transformer on a pad, held by a dished washer, a bolt from below and a nut.
  const c = CORE;
  const arc = (cx: number, cz: number, from: number): P2[] =>
    Array.from({ length: 5 }, (_, i): P2 => [cx + c.round * Math.cos(from + (i * Math.PI) / 8), cz + c.round * Math.sin(from + (i * Math.PI) / 8)]);
  const z1 = sheet + 1.5;
  const section = [
    ...arc(c.inner + c.round, z1 + c.round, Math.PI), ...arc(c.outer - c.round, z1 + c.round, 1.5 * Math.PI),
    ...arc(c.outer - c.round, z1 + c.height - c.round, 0), ...arc(c.inner + c.round, z1 + c.height - c.round, 0.5 * Math.PI),
  ];
  const place = (s: Shape): Shape => translate(s, [c.x, c.y, 0]);
  part(brass, place(own(lathe(section))));
  part(dark, place(own(lathe([[2.6, sheet], [c.outer - 2, sheet], [c.outer - 2, z1], [2.6, z1]]))));
  part(steel, place(own(lathe([[2.6, z1 + c.height], [15, z1 + c.height], [15, z1 + c.height + 1.5], [2.6, z1 + c.height + 1.5]]))));
  const nutAt = z1 + c.height + 1.5;
  const plain = M5.length - M5.thread;
  part(steel, place(own(compound([
    own(translate(own(hexagon(M5.flats, M5.headHeight)), [0, 0, -M5.headHeight])),
    own(cylinder(M5.major / 2, plain)),
    own(cylinder(M5.minor / 2, M5.thread, { at: [0, 0, plain] })),
    own(screwTooth(M5, plain, M5.length)),
  ]) as Shape)));
  part(steel, place(own(unwrap(cut(own(translate(own(hexagon(M5.flats, M5.nutHeight)), [0, 0, nutAt])), own(cylinder(M5.major / 2 + PLAY, M5.nutHeight + 2, { at: [0, 0, nutAt - 1] })))) as Shape)));
  part(steel, place(own(nutTooth(M5, nutAt, nutAt + M5.nutHeight))));

  // Two can capacitors with their terminals.
  for (const x of [8, 34]) {
    part(dark, cylinder(11, 33, { at: [x, 30, sheet] }));
    part(steel, cylinder(10, 1, { at: [x, 30, sheet + 33] }));
    for (const dy of [-4.5, 4.5]) part(brass, cylinder(2, 2.5, { at: [x, 30 + dy, sheet + 34] }));
  }

  // Regulator board at the rear: terminal block, heat sink with two transistors, capacitors and a rectifier.
  const bx = -38;
  const zb = sheet + 6;
  const zt = zb + 1.6;
  const stand: P2[] = [[bx + 22, 40], [bx - 22, 40], [bx - 22, -40], [bx + 22, -40]];
  const board = unwrap(cutAll(own(brick(52, 88, 1.6, bx, 0, zb)), stand.map(([x, y]) => own(cylinder(1.6, 4, { at: [x, y, zb - 1] }))))) as Shape;
  // Tapped standoffs. Each board screw goes 4.4 mm into the thread of its standoff.
  const post = own(compound([
    own(unwrap(cut(own(hexagon(5.5, 6)), own(cylinder(M3.major / 2 + PLAY, 6, { at: [0, 0, 1] })))) as Shape),
    own(nutTooth(M3, 1.4, 6)),
  ]) as Shape);
  const boardScrew = own(panScrew(6));
  stand.forEach(([x, y]) => {
    part(brass, translate(post, [x, y, sheet]));
    part(steel, translate(boardScrew, [x, y, zt + k]));
  });
  const ways = [-1.5, -0.5, 0.5, 1.5].map((i) => c.y + i * 2 * GRID);
  const tx = bx + 22;
  const wireTop = zt + 4.6;
  part(orange, unwrap(cutAll(own(brick(8, 4 * 2 * GRID, 10, tx, c.y, zt)), ways.flatMap((y) => [
    own(cylinder(1.5, 5, { at: [tx, y, zt + 3.6], axis: [1, 0, 0] })),
    own(cylinder(M3.major / 2 + PLAY, 8, { at: [tx + 1.5, y, zt + 3.6] })),
  ]))) as Shape);
  // Slotted set screw in the tapped hole of each way. Its flat point is on the wire.
  const slot = own(brick(4, SET.slot, 1, 0, 0, SET.length - SET.slotDepth));
  const setScrew = own(compound([
    own(unwrap(cut(own(cylinder(M3.minor / 2, SET.length)), slot)) as Shape),
    own(unwrap(cut(own(screwTooth(M3, 0, SET.length)), slot)) as Shape),
  ]) as Shape);
  const wayTooth = own(nutTooth(M3, 0.6, zt + 10 - wireTop));
  ways.forEach((y, i) => {
    part(steel, translate(setScrew, [tx + 1.5, y, wireTop]));
    part(orange, translate(wayTooth, [tx + 1.5, y, wireTop]));
    // Transformer lead: from the winding straight into its terminal.
    const reach = Math.sqrt(c.outer * c.outer - (Math.abs(y - c.y) - 1) ** 2);
    part(i < 2 ? orange : white, cylinder(1, c.x - reach - tx, { at: [tx, y, zt + 3.6], axis: [1, 0, 0] }));
  });
  const fins: P2[] = [[-12, 0], [12, 0], [12, 9]];
  for (let i = 0; i < 5; i++) fins.push([10 - i * 4.4, 9], [10 - i * 4.4, 2.5], [7.6 - i * 4.4, 2.5], [7.6 - i * 4.4, 9]);
  fins.push([-12, 9]);
  part(steel, prism(fins.map(([a, b]): P3 => [bx - 8 - b, 24 + a, zt]), [0, 0, 26]));
  for (const y of [17, 31]) {
    part(steel, unwrap(cut(own(brick(1.3, 10, 16, bx - 7.35, y, zt + 4)), own(cylinder(1.8, 3, { at: [bx - 9, y, zt + 17], axis: [1, 0, 0] })))) as Shape);
    part(dark, brick(3.2, 10, 9, bx - 5.1, y, zt + 4));
    for (const dy of [-GRID, 0, GRID]) part(steel, brick(0.5, 0.8, 4, bx - 5.6, y + dy, zt));
  }
  for (const [x, y] of [[bx - 12, -8], [bx - 12, -26]] as const) {
    part(dark, cylinder(6.3, 19.6, { at: [x, y, zt] }));
    part(steel, cylinder(5.6, 0.4, { at: [x, y, zt + 19.6] }));
  }
  part(dark, unwrap(cut(own(brick(5, 19, 15, bx + 6, 0, zt + 1.5)), own(cylinder(1.7, 7, { at: [bx + 3, 0, zt + 9], axis: [1, 0, 0] })))) as Shape);
  for (let i = 0; i < 4; i++) part(steel, brick(0.8, 0.8, 1.5, bx + 6, (i - 1.5) * 2 * GRID, zt));

  return {
    base, cover, board,
    feet: compound(feet) as Shape,
    groups: [dark, steel, brass, orange, white].map((list) => compound(list) as Shape),
    openMeasured, openFormula,
  };
}

const built = freeing(() => ventedCase());
console.log('Side vents: ' + built.openMeasured.toFixed(1) + ' % open area from the kernel volumes. The handbook formula gives ' + built.openFormula.toFixed(1) + ' %.');

export default [
  color(built.base, '#f5f2ea'),
  color(built.feet, '#48515c'),
  color(built.cover, '#12b5b0'),
  color(built.board, '#0c7f7b'),
  ...built.groups.map((g, i) => color(g, ['#48515c', '#c3c9d1', '#d3a956', '#ff5a1f', '#f5f2ea'][i]!)),
];

Functions used ​

box compound cut cutAll cylinder edgeFinder extrude fillet fuseAll line loft measureVolume polygon revolve rotate translate unwrap wire color

▶ Run Vented Louvre Instrument Case in the playground

Released under the Apache 2.0 License.