Skip to content

Green PCB Terminal Block ​

Green PCB Terminal Block, rendered in the brepjs playground
Mechanical · 189 lines▶ Run it in the playground

A green 5.08 mm rising-clamp terminal block on a board edge, with the two end poles in half section: screws, clamp cages, current bars, pins and 2.5 mm2 wires. The pitch, the body height and depth, the pins, the M2.5 screw thread and the wire size are published figures. Each screw is a true helix in the threaded top of its cage, and it turns once for each 0.45 mm that the clamp parameter lifts the cage. The kernel measures the body length against the pitch rule. The cages, the bars, the body cavities and the board 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, extrude, getBounds, line, loft, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// 5.08 mm rising-clamp terminal block on a board edge, with the two end poles in half section. Units are mm.
// The pitch, the body height and depth, the pins, the screw size and the wire size are published figures.
// The clamp cage, the current bar, the body cavities and the board are a display model.
interface TerminalBlockParams {
  poles?: number; // 2 to 12, as in the datasheet
  clamp?: number; // 0 = cage open, 1 = cage tight on the wire. The screws turn once for each 0.45 mm of cage travel.
  cutaway?: boolean; // false leaves the body whole
}

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 PITCH = 5.08; // the block is poles x 5.08 long
const BODY = { height: 14.1, depth: 10.3 };
const PIN = { length: 3.5, width: 0.9, thick: 0.5 };
const SCREW = { major: 2.5, minor: 2.013, pitch: 0.45 }; // M2.5, ISO coarse, right-hand
const WIRE = { area: 2.5, strip: 7 }; // mm2 of copper, and the stripped length

// ---- display model
const SCREW_Y = 5; // screw axis, from the wire face
const HEAD = { radius: 1.9, height: 1.6, seat: 12.3 };
const BAR = { bottom: 6, thick: 0.6, half: 1.2 }; // fixed current bar inside the cage
const CAGE = { half: 1.8, front: 1.5, back: 7.5, height: 6.2, wall: 0.5, nut: 1.8, open: 2.5 }; // nut = threaded top, open = cage bottom at clamp 0
const PLAY = 0.06; // radial clearance between the screw thread and the cage thread
const CAVITY = { half: 1.9, front: 1, back: 8.9, bottom: 1.5, top: 10.2 };
const BOARD = { thick: 1.6, lip: 2, back: 16, side: 3 };
const JACKET = { radius: 1.5, length: 8 };

const block = (x0: number, x1: number, y0: number, y1: number, z0: number, z1: number): Shape =>
  box(x1 - x0, y1 - y0, z1 - z0, { at: [(x0 + x1) / 2, (y0 + y1) / 2, (z0 + z1) / 2] });

// 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;
};

// One helical thread tooth about Z, from z0 to z1. 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 bore: ref is half a pitch away.
// The loft is smooth, so each flank is one helical face. A long loft drifts off the helix: a long thread is pieces of 4 turns.
const SECTIONS = 12; // sections of the loft in each turn
const SLACK = 0.998; // keeps the tooth of a screw a hair clear of its core
const BORE_SLACK = 0.99; // and the tooth in a bore clear of the wall
const helixTooth = (core: number, tip: number, pitch: number, z0: number, z1: number, ref: number): Shape => {
  const root = tip > core ? core / SLACK : core * BORE_SLACK;
  const crest = tip > core ? tip : tip / SLACK;
  const half = 0.42 * pitch;
  const piece = (from: number, to: number): Shape => {
    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): 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;
  };
  const count = Math.max(1, Math.ceil((z1 - z0) / (4 * pitch) - 0.001));
  const pieces = Array.from({ length: count }, (_, i) => piece(z0 + ((z1 - z0) * i) / count, z0 + ((z1 - z0) * (i + 1)) / count));
  return count === 1 ? pieces[0]! : (compound(pieces.map(own)) as Shape);
};

// The same tooth, only where its angle about Z is from a0 to a1 degrees: one piece for each turn.
// A section through the axis needs no boolean cut this way.
const helixArcs = (core: number, tip: number, pitch: number, z0: number, z1: number, ref: number, a0: number, a1: number): Shape[] => {
  const pieces: Shape[] = [];
  for (let k = Math.floor((z0 - ref) / pitch) - 2; ref + (k + a0 / 360) * pitch < z1; k++) {
    const from = Math.max(z0, ref + (k + a0 / 360) * pitch);
    const to = Math.min(z1, ref + (k + a1 / 360) * pitch);
    if (to - from > 0.04 * pitch) pieces.push(helixTooth(core, tip, pitch, from, to, ref));
  }
  return pieces;
};

// Built with the length along X and the wire face at y = 0. The last lines turn the wire face to +X.
function terminalBlock({ poles = 4, clamp = 1, cutaway = true }: TerminalBlockParams = {}) {
  const n = Math.min(Math.max(Math.round(poles), 2), 12);
  const length = n * PITCH;
  const centres = Array.from({ length: n }, (_, i) => (i + 0.5) * PITCH);
  const each = (s: Shape): Shape[] => centres.map((x) => own(translate(s, [x, 0, 0]) as Shape));
  const rw = Math.sqrt(WIRE.area / Math.PI); // radius of a solid 2.5 mm2 conductor
  const rise = Math.min(Math.max(clamp, 0), 1) * (BAR.bottom - 2 * rw - (CAGE.open + CAGE.wall));
  const cageBottom = CAGE.open + rise;

  // Body: one extruded section, then the cavity, wire window, screw well and pin slot of each pole.
  const section = own(unwrap(polygon(([[0, 0], [0, 8], [2.6, BODY.height], [7.4, BODY.height], [BODY.depth, 9.5], [BODY.depth, 0]] as P2[]).map(([y, z]): P3 => [0, y, z]))));
  const blank = own(unwrap(extrude(section, [length, 0, 0])) as Shape);
  const hollow = [
    block(-CAVITY.half, CAVITY.half, CAVITY.front, CAVITY.back, CAVITY.bottom, CAVITY.top),
    block(-CAGE.half, CAGE.half, -1, 2, 2, 7.5),
    cylinder(HEAD.radius + 0.1, 3, { at: [0, SCREW_Y, HEAD.seat] }),
    cylinder(SCREW.major / 2 + 0.1, 4, { at: [0, SCREW_Y, CAVITY.top - 1] }),
    block(-PIN.width / 2, PIN.width / 2, 8.1, 8.1 + PIN.thick, -1, CAVITY.bottom + 1),
  ].flatMap((s) => each(own(s)));
  const ends = cutaway ? [own(block(-1, PITCH / 2, -1, 12, -1, 16)), own(block(length - PITCH / 2, length + 1, -1, 12, -1, 16))] : [];
  const body = unwrap(cutAll(blank, [...hollow, ...ends])) as Shape;

  // Screw: a slotted head in the well and an M2.5 helix down to the current bar. The body holds it, so it only turns.
  // A right-hand screw that turns clockwise from above lifts the cage by one pitch for each turn.
  const r = SCREW.major / 2;
  const core = SCREW.minor / 2;
  const tip = BAR.bottom + BAR.thick;
  const runout = HEAD.seat - 1.2; // the thread ends here, under a plain shank
  const top = HEAD.seat + HEAD.height;
  const turnedBlank = own(lathe([[0, tip], [core - 0.15, tip], [core, tip + 0.15], [core, runout], [r, runout], [r, HEAD.seat], [HEAD.radius, HEAD.seat], [HEAD.radius, top - 0.3], [HEAD.radius - 0.3, top], [0, top]]));
  const slotted = own(unwrap(cut(turnedBlank, own(rotate(own(block(-3, 3, -0.3, 0.3, top - 0.8, top + 1)), 35) as Shape))) as Shape);
  const thread = own(helixTooth(core, r, SCREW.pitch, tip + 0.35, runout - 0.2, 0));
  const spin = (-360 * rise) / SCREW.pitch;
  const screws = [slotted, thread].flatMap((s) => each(own(translate(own(rotate(s, spin) as Shape), [0, SCREW_Y, 0]) as Shape)));

  // Cage: a brass frame with a threaded top that the screw lifts. The wire lies on its floor, under the fixed bar.
  // The cage thread is half a pitch from the screw thread and moves up with the cage. The end cages are cut with the body.
  const cageTop = cageBottom + CAGE.height;
  const frame = own(unwrap(cutAll(own(block(-CAGE.half, CAGE.half, CAGE.front, CAGE.back, cageBottom, cageTop)), [
    own(block(-CAGE.half + CAGE.wall, CAGE.half - CAGE.wall, 0, 9, cageBottom + CAGE.wall, cageTop - CAGE.nut)),
    own(cylinder(r + PLAY, CAGE.nut + 2, { at: [0, SCREW_Y, cageTop - CAGE.nut - 1] })),
  ])) as Shape);
  // A cut cage keeps the half of its thread on the side that stays: +X at the first pole, -X at the last.
  const span = [r + PLAY, core + PLAY, SCREW.pitch, cageTop - CAGE.nut + 0.2, cageTop - 0.2, SCREW.pitch / 2 + rise] as const;
  const onAxis = (teeth: Shape[]): Shape[] => teeth.map((s) => own(translate(own(s), [0, SCREW_Y, 0]) as Shape));
  const whole = onAxis([helixTooth(...span)]);
  const halves = [onAxis(helixArcs(...span, -90, 90)), onAxis(helixArcs(...span, 90, 270))];
  const cages = centres.flatMap((x, i) => {
    const end = ends.length && (i === 0 || i === n - 1) ? (i === 0 ? 0 : 1) : -1;
    const parts = end < 0 ? [frame, ...whole] : [own(unwrap(cut(own(translate(frame, [x, 0, 0]) as Shape), ends[end]!)) as Shape), ...halves[end]!.map((s) => own(translate(s, [x, 0, 0]) as Shape))];
    return end < 0 ? parts.map((s) => own(translate(s, [x, 0, 0]) as Shape)) : parts;
  });

  // Current bar and pin: one bent strip of tinned brass.
  const back = 8.1 + PIN.thick;
  const bars = [
    ...each(own(block(-BAR.half, BAR.half, 2, back, BAR.bottom, tip))),
    ...each(own(block(-PIN.width / 2, PIN.width / 2, 8.1, back, -PIN.length, BAR.bottom))),
  ];

  // Wires: a solid conductor of the published area, stripped for the published length.
  const zw = cageBottom + CAGE.wall + rw;
  const copper = each(own(cylinder(rw, WIRE.strip, { at: [0, -0.5, zw], axis: [0, 1, 0] })));
  const jackets = each(own(cylinder(JACKET.radius, JACKET.length, { at: [0, -0.5 - JACKET.length, zw], axis: [0, 1, 0] })));

  // Board: the block sits at its edge. Each pin has a hole, a pad and a track.
  const drills = each(own(cylinder(0.65, 4, { at: [0, 8.1 + PIN.thick / 2, -3] })));
  const board = unwrap(cutAll(own(block(-BOARD.side, length + BOARD.side, -BOARD.lip, BOARD.back, -BOARD.thick, 0)), drills)) as Shape;
  const tracks = each(own(block(-1.2, 1.2, BODY.depth, BOARD.back - 2, 0, 0.07)));

  const turn = (s: Shape): Shape => rotate(own(s), 90) as Shape;
  const group = (parts: Shape[]): Shape => turn(compound(parts) as Shape);
  return {
    body: turn(body),
    screws: group(screws),
    cages: group(cages),
    bars: group(bars),
    copper: group(copper),
    jackets: [group(jackets.filter((_, i) => i % 2 === 0)), group(jackets.filter((_, i) => i % 2 === 1))],
    board: turn(board),
    tracks: group(tracks),
    length: getBounds(blank).xMax - getBounds(blank).xMin,
    poles: n,
  };
}

const part = freeing(() => terminalBlock());
console.log('Body length: ' + part.length.toFixed(2) + ' mm from the kernel bounds. The datasheet rule is ' + part.poles + ' x 5.08 = ' + (part.poles * PITCH).toFixed(2) + ' mm.');

export default [
  color(part.body, '#3cb563'),
  color(part.screws, '#f5f2ea'),
  color(part.cages, '#d3a956'),
  color(part.bars, '#c3c9d1'),
  color(part.copper, '#c9783c'),
  color(part.jackets[0]!, '#ff5a1f'),
  color(part.jackets[1]!, '#f5f2ea'),
  color(part.board, '#48515c'),
  color(part.tracks, '#d3a956'),
];

Functions used ​

box compound cut cutAll cylinder extrude getBounds line loft polygon revolve rotate translate unwrap wire color

▶ Run Green PCB Terminal Block in the playground

Released under the Apache 2.0 License.