Wire Fan Guard (80 mm)

A wire-form finger guard for an 80 mm fan: five welded rings on two bent ribs that end in mounting eyes, lifted off the fan with its four M4 pan-head screws. Each screw has a true helical thread and a nut behind the fan flange, and it turns once for each 0.7 mm that it backs out. The wire diameters, the 76.2 mm outside diameter, the eye pitch, the height and the M4 thread are published figures. The kernel measures the steel mass, and the ring gap is compared with the 12 mm test finger. The ring count, the rib path, the screw length and the fan are a display model.
Code
This is the full program. The playground runs it in your browser without a change.
import { box, circle, compound, cutAll, cylinder, edgeFinder, extrude, face, fillet, fuseAll, interpolateCurve, intersect, line, loft, measureVolume, mirror, polygon, revolve, rotate, sphere, torus, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';
// Wire-form finger guard for an 80 mm fan, with its four M4 screws and nuts and the fan. Z is the fan axis, units are millimetres.
// The ring and rib wire, the outside diameter, the eye pitch and the height are published figures.
// The M4 thread and hardware sizes are published too. The ring count, the rib path, the screw length and the fan are a display model.
interface GuardParams {
rings?: number; // concentric rings between the inner and the outer diameter
lift?: number; // 0 = installed, 1 = guard and screws off the fan. A screw turns once for each pitch that it rises
fan?: boolean; // false shows the guard and the screws alone
}
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 (wire-form guard for an 80 mm fan)
const OUTSIDE = 76.2; // outside diameter of the largest ring
const INSIDE = 14.2; // inside diameter of the smallest ring
const WIRE = { ring: 1.6, rib: 1.8 }; // wire diameters
const EYES = { pitch: 71.37, hole: 4.57 }; // mounting eyes at the ends of the ribs
const HEIGHT = 4.95; // from the mounting face to the top of the rings
const FAN = { side: 80, depth: 25, pitch: 71.5, hole: 4.5, flange: 4 }; // 80 x 80 x 25 mm fan frame
const TEST_FINGER = 12; // diameter of the jointed test finger
const SCREW = { thread: 4, minor: 3.242, head: 8, headHeight: 3.1, pitch: 0.7 }; // M4 coarse thread, right hand, pan head
const NUT = { flats: 7, height: 3.2 }; // M4 hexagon nut
const STEEL = 7.85e-3; // grams per cubic millimetre
// ---- display model
const WELD = 0.2; // how far a ring sinks into a rib at a weld
const APEX = 6; // bend radius where a rib turns at the centre
const JOG = { from: 40.5, to: 44.5 }; // where a rib steps down to the mounting face
const SCREW_LENGTH = 12;
const PLAY = 0.06; // radial play between the screw thread and the nut thread
const BORE = 38; // radius of the air duct of the fan
const HUB = 19; // radius of the impeller hub
const BLADES = 7;
const TILT = 55; // degrees that the axis leans toward +X for the view
// 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;
};
const ring = (r0: number, r1: number, z0: number, z1: number): Shape => lathe([[r0, z0], [r1, z0], [r1, z1], [r0, z1]]);
const turn = (s: Shape, deg: number): Shape => rotate(s, deg, { 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.
// tip > core is the thread on a core of the radius core. tip < core is the thread in a bore of the radius core.
// The loft is smooth: each flank is one helical face.
const SECTIONS = 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 outward = tip > core;
const root = outward ? core / SLACK : core * SLACK;
const crest = outward ? tip : tip / SLACK;
const half = 0.42 * pitch; // half width of the tooth at its root
const n = Math.max(2, Math.round(((to - from) / pitch) * SECTIONS));
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): [number, number, number] => [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; // loft is ruled by default
};
// A round wire from p to q.
const rod = (p: P3, q: P3, r: number): Shape => {
const d: P3 = [q[0] - p[0], q[1] - p[1], q[2] - p[2]];
return own(cylinder(r, Math.hypot(d[0], d[1], d[2]), { at: p, axis: d }));
};
function guard({ rings = 5, lift = 0.5, fan = true }: GuardParams = {}) {
const rr = WIRE.ring / 2;
const rb = WIRE.rib / 2;
const zRing = HEIGHT - rr;
const zRib = zRing - rr - rb + WELD;
const k = Math.SQRT1_2;
// Rings: evenly spaced circles of wire.
const rMin = INSIDE / 2 + rr;
const rMax = OUTSIDE / 2 - rr;
const count = Math.max(2, Math.round(rings)); // one ring has no spacing
const step = (rMax - rMin) / (count - 1);
const ringSet = Array.from({ length: count }, (_, i) => own(torus(rMin + i * step, rr, { at: [0, 0, zRing] })));
// Rib: one wire from an eye toward the centre, around a bend, and out to the next eye.
// It runs under the rings and steps down to the mounting face near each eye.
const eyeAt = (EYES.pitch / 2) * Math.SQRT2;
const loop = EYES.hole / 2 + rb;
const on = (s: number, z: number): P3 => [s * k, s * k, z]; // a point on the diagonal, s from the centre
const leg = [
rod(on(APEX, zRib), on(JOG.from, zRib), rb),
own(sphere(rb, { at: on(JOG.from, zRib) })),
rod(on(JOG.from, zRib), on(JOG.to, rb), rb),
own(sphere(rb, { at: on(JOG.to, rb) })),
rod(on(JOG.to, rb), on(eyeAt - loop, rb), rb),
own(torus(loop, rb, { at: on(eyeAt, rb) })),
];
const outline = own(unwrap(wire([own(circle(rb, { at: on(APEX, zRib), axis: [k, k, 0] }))])));
const round = own(unwrap(face(outline as never)));
const bend = own(unwrap(revolve(round, { axis: [0, 0, 1], at: [0, APEX * Math.SQRT2, 0], angle: Math.PI / 2 })) as Shape);
const rib = own(unwrap(fuseAll([...leg, bend, ...leg.map((s) => own(mirror(s, { normal: [1, 0, 0] }) as Shape))])) as Shape);
const welded = unwrap(fuseAll([...ringSet, rib, own(turn(rib, 180))])) as Shape;
// M4 pan-head screw: a cross recess, and one helical tooth on the core from the point to the head.
const half = FAN.pitch / 2;
const top = 2 * rb;
const crest = SCREW.thread / 2;
const rm = SCREW.minor / 2;
const edge = 0.42 * SCREW.pitch; // a tooth ends this far from the end of its thread
const point = top - SCREW_LENGTH;
const blankScrew = own(lathe([
[0, top + SCREW.headHeight], [SCREW.head / 2 - 1.2, top + SCREW.headHeight], [SCREW.head / 2, top + 1], [SCREW.head / 2, top],
[rm, top], [rm, point + 0.4], [rm - 0.4, point], [0, point],
]));
const slot = (w: number, d: number): Shape => own(box(w, d, 1.8, { at: [0, 0, top + SCREW.headHeight] }));
const headed = own(unwrap(cutAll(blankScrew, [slot(4.6, 0.9), slot(0.9, 4.6)])) as Shape);
const screw = own(compound([headed, own(helixTooth(rm, crest, SCREW.pitch, point + 0.4 + edge, top - edge, 0))]) as Shape);
// Nut behind the front flange: bored to the major diameter, with the mating tooth half a pitch from the screw's.
const tap = crest + PLAY;
const zn = -FAN.flange - NUT.height;
const rc = NUT.flats / Math.sqrt(3);
const hex = own(unwrap(polygon(Array.from({ length: 6 }, (_, i): P3 => [rc * Math.cos((i * Math.PI) / 3), rc * Math.sin((i * Math.PI) / 3), zn]))));
const nutBody = own(unwrap(cutAll(own(unwrap(extrude(hex, [0, 0, NUT.height])) as Shape), [own(cylinder(tap, NUT.height + 2, { at: [0, 0, zn - 1] }))])) as Shape);
const nut = own(compound([nutBody, own(helixTooth(tap, rm + PLAY, SCREW.pitch, zn + edge, -FAN.flange - edge, SCREW.pitch / 2))]) as Shape);
// Exploded state: the guard lifts off the fan. Each screw backs out of its nut by one turn for each pitch.
const corners: P2[] = [[1, 1], [-1, 1], [-1, -1], [1, -1]];
const rise = 36 * lift;
const backedOut = own(turn(screw, (360 * rise) / SCREW.pitch));
const screws = corners.map(([x, y]) => own(translate(backedOut, [x * half, y * half, rise]) as Shape));
const nuts = corners.map(([x, y]) => own(translate(nut, [x * half, y * half, 0]) as Shape));
const lean = (s: Shape): Shape => rotate(s, TILT, { axis: [0, 1, 0] }) as Shape;
const grams = unwrap(measureVolume(welded)) * STEEL;
return {
guard: lean(own(translate(welded, [0, 0, 16 * lift]) as Shape)), screws: lean(own(compound(screws) as Shape)),
fan: fan ? fanBody().map((s) => lean(own(s))) : [], nuts: fan ? [lean(own(compound(nuts) as Shape))] : [], grams, gap: step - WIRE.ring,
};
}
// One aerofoil section on the cylinder of radius r. pitch is the angle between the chord and the plane of rotation.
const section = (r: number, chord: number, pitch: number, lead: number, z0: number) => {
const at = (x: number, side: 1 | -1): P3 => {
const yt = 0.3 * (0.2969 * Math.sqrt(x) - 0.126 * x - 0.3516 * x * x + 0.2843 * x ** 3 - 0.1036 * x ** 4);
const a = (0.5 - x) * chord;
const b = (0.28 * x * (1 - x) + side * yt) * chord;
const angle = lead + (a * Math.cos(pitch) - b * Math.sin(pitch)) / r;
return [r * Math.cos(angle), r * Math.sin(angle), z0 + a * Math.sin(pitch) + b * Math.cos(pitch)];
};
const xs = Array.from({ length: 11 }, (_, i) => 0.5 * (1 - Math.cos((Math.PI * i) / 10)));
const upper = own(unwrap(interpolateCurve(xs.map((x) => at(x, 1)))));
const lower = own(unwrap(interpolateCurve(xs.map((x) => at(x, -1)).reverse())));
return own(unwrap(wire([upper, lower])));
};
// The fan under the guard: frame and impeller only. Its front face is the plane z = 0.
function fanBody(): Shape[] {
const d2r = Math.PI / 180;
const zf = -FAN.flange / 2;
const plate = own(box(FAN.side, FAN.side, FAN.flange, { at: [0, 0, zf] }));
const flange = own(unwrap(fillet(plate, edgeFinder().inDirection('Z').findAll(plate), (FAN.side - FAN.pitch) / 2)) as Shape);
const far = own(translate(flange, [0, 0, FAN.flange - FAN.depth]) as Shape);
const blank = own(unwrap(fuseAll([flange, far, own(ring(BORE - 1, BORE + 1.5, 1 - FAN.depth, -1))])) as Shape);
const duct = own(lathe([[0, 1], [BORE + 2.2, 1], [BORE, -2.2], [BORE, 1.6 - FAN.depth], [BORE + 1.6, -1 - FAN.depth], [0, -1 - FAN.depth]]));
const hole = own(cylinder(FAN.hole / 2, FAN.depth + 2, { at: [FAN.pitch / 2, FAN.pitch / 2, -1 - FAN.depth] }));
const quarter = (s: Shape): Shape[] => [0, 90, 180, 270].map((a) => own(turn(s, a)));
const shell = own(unwrap(cutAll(blank, [duct, ...quarter(hole)])) as Shape);
const strut = own(box(BORE - 9, 3, 3, { at: [(BORE + 11) / 2, -6, 1.5 - FAN.depth] }));
const frame = unwrap(fuseAll([shell, own(cylinder(HUB, 3, { at: [0, 0, -FAN.depth] })), ...quarter(strut)])) as Shape;
const z0 = 4.6 - FAN.depth;
const cup = lathe([[0, z0 - 1.6], [4, z0 - 1.6], [4, -2], [HUB - 1.2, -2], [HUB - 1.2, z0], [HUB, z0], [HUB, -1.3], [HUB - 0.8, -0.5], [0, -0.5]]);
const stations: [number, number, number, number][] = [[16.5, 19, 55, -1], [24, 25, 42, 4], [31.5, 29, 33, 10], [39.5, 31, 26, 19]]; // r, chord, pitch, lead
const raw = own(unwrap(loft(stations.map(([r, chord, pitch, lead]) => section(r, chord, pitch * d2r, lead * d2r, 14.5 - FAN.depth)), { ruled: false })) as Shape);
const blade = own(unwrap(intersect(raw, own(ring(HUB, BORE - 1, -FAN.depth, 0)))) as Shape);
const blades = Array.from({ length: BLADES }, (_, i) => own(turn(blade, (360 * i) / BLADES)));
return [frame, compound([own(cup), ...blades]) as Shape];
}
const part = freeing(() => guard());
console.log('Guard: ' + part.grams.toFixed(1) + ' g of steel wire from the kernel volume.');
console.log('Gap between rings: ' + part.gap.toFixed(2) + ' mm. The test finger is ' + TEST_FINGER + ' mm in diameter.');
export default [
color(part.guard, '#c3c9d1'),
color(part.screws, '#d3a956'),
...part.nuts.map((s) => color(s, '#d3a956')),
...part.fan.map((s, i) => color(s, i === 0 ? '#f5f2ea' : '#12b5b0')),
];Functions used
box circle compound cutAll cylinder edgeFinder extrude face fillet fuseAll interpolateCurve intersect line loft measureVolume mirror polygon revolve rotate sphere torus translate unwrap wire color