Skip to content

Butt Hinge on a Door ​

Butt Hinge on a Door, rendered in the brepjs playground
Mechanical · 169 lines▶ Run it in the playground

A 4-1/2 x 4-1/2 in full-mortise butt hinge of standard weight, on a door edge and its frame, with eight No. 12 wood screws. The hinge size, the gauge, the knuckle diameter, the swage and the screw-hole pattern are the published template dimensions. Each screw has the published 11 threads per inch as a true helix, in the thread that it forms in the wood. The open parameter swings the door side about the pin. The pin, the thread depth, the door and the frame are a display model.

Code ​

This is the full program. The playground runs it in your browser without a change.

ts
import { box, compound, cone, cutAll, cylinder, extrude, fuseAll, line, loft, polygon, revolve, rotate, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// Full-mortise butt hinge, 4-1/2 x 4-1/2 in, standard weight, on a door edge and its frame.
// The hinge size, the gauge, the knuckle, the swage and the screw holes are the published template.
// The screws have the published 11 threads per inch as a true helix, and the wood has the thread that they form.
// The pin, the thread depth, the door and the frame are a display model. Units are millimetres, the pin is on Z.
interface HingeParams {
  open?: number; // door angle in degrees: 0 is closed, 180 is flat open
  screws?: boolean; // false shows the empty countersunk holes
  section?: boolean; // cut the wood through the top screws to show them in the wood
  context?: boolean; // false shows the hinge without the door and the frame
}

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 (template hinge, 5 knuckles, 0.134 in gauge)
const HEIGHT = 114.3; // along the pin
const WIDTH = 114.3; // across both leaves when the hinge is flat open
const GAUGE = 3.4; // leaf thickness
const KNUCKLE = { count: 5, diameter: 15.48 };
const SWAGE = 47.63; // leaf edge to the swage line
const LEAF_GAP = 1.59; // between the leaves when the door is closed
const HOLES = { along: [12.9, 41.48, 72.82, 101.4], inset: [25.4, 9.53, 9.53, 25.4] }; // from the end, from the leaf edge
const SCREW = { major: 5.49, head: 11.13, angle: 82, length: 31.75, pitch: 25.4 / 11 }; // No. 12 x 1-1/4 in flat head wood screw, 11 threads per inch
const DOOR = { thickness: 44.45, backset: 6.35 }; // 1-3/4 in door, leaf edge 1/4 in from the far face

// ---- display model
const PIN = { radius: 3.3, cap: 2.6 };
const THREAD = { turns: 8, root: 1.8, tip: 3.2, play: 0.1 }; // 8 turns and the point are about 2/3 of the length
const WOOD = { margin: 24, door: 70, jamb: 19, jambWidth: 86, post: 38, stop: { thick: 11, width: 35 } };

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] }));

// 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]): [number, number, number] => [r, 0, z]))));
  return own(unwrap(revolve(profile, { axis: [0, 0, 1] }))) as Shape;
};

// A 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, tip < core is the thread in a hole. Right hand.
const FACETS = 12; // sections of the smooth loft in each turn. Each flank is one helical face
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 own(unwrap(loft(sections, { ruled: false }))) as Shape;
};

function hinge({ open = 150, screws = true, section = true, context = true }: HingeParams = {}) {
  const swing = Math.min(180, Math.max(0, open));
  const half = WIDTH / 2; // pin centre to the leaf edge
  const r = KNUCKLE.diameter / 2;
  const x0 = LEAF_GAP / 2;
  const x1 = x0 + GAUGE;
  const neck = SWAGE - half; // the swage line, where the flat leaf starts to curl
  const pitch = HEIGHT / KNUCKLE.count;
  const headDepth = (SCREW.head - SCREW.major) / 2 / Math.tan((SCREW.angle * Math.PI) / 360);
  const holes = HOLES.along.map((z, i): P2 => [HOLES.inset[i]! - half, z]);

  // One leaf, closed position. side +1 is the frame leaf (x > 0), side -1 the door leaf.
  const leaf = (side: 1 | -1, knuckles: number[]): Shape => {
    const plate = side > 0 ? block(x0, x1, -half, neck, 0, HEIGHT) : block(-x1, -x0, -half, neck, 0, HEIGHT);
    const curls = knuckles.flatMap((i) => {
      const z0 = i === 0 ? 0 : i * pitch + 0.15;
      const z1 = i === KNUCKLE.count - 1 ? HEIGHT : (i + 1) * pitch - 0.15;
      const wrap: P2[] = [[x0, neck], [x1, neck], [0.95 * r * Math.cos(0.45), -0.95 * r * Math.sin(0.45)], [x0, -0.4 * r]];
      const section = own(unwrap(polygon(wrap.map(([x, y]): [number, number, number] => [side * x, y, z0]))));
      return [own(unwrap(extrude(section, [0, 0, z1 - z0]))) as Shape, own(cylinder(r, z1 - z0, { at: [0, 0, z0] }))];
    });
    const sinks = holes.flatMap(([y, z]) => [
      own(cone(SCREW.head / 2, SCREW.major / 2, headDepth, { at: [side * x0, y, z], axis: [side, 0, 0] })),
      own(cylinder(SCREW.major / 2, GAUGE + 2, { at: [side * (x0 - 1), y, z], axis: [side, 0, 0] })),
    ]);
    const bore = own(cylinder(PIN.radius, HEIGHT + 2, { at: [0, 0, -1] }));
    return own(unwrap(cutAll(own(unwrap(fuseAll([plate, ...curls]))), [bore, ...sinks]))) as Shape;
  };

  // Pin with a button tip at each end.
  const cap = PIN.cap;
  const pin = lathe([
    [0, -cap], [r - 1.5, -cap], [r, -cap / 2], [r, 0], [PIN.radius, 0],
    [PIN.radius, HEIGHT], [r, HEIGHT], [r, HEIGHT + cap / 2], [r - 1.5, HEIGHT + cap], [0, HEIGHT + cap],
  ]);

  // One wood screw along +Z, head face at z = 0: countersunk head, shank, core and cone point, with one helical tooth.
  const crest = SCREW.major / 2;
  const tipStart = SCREW.length - THREAD.tip;
  const threadStart = tipStart - THREAD.turns * SCREW.pitch;
  const flank = 0.42 * SCREW.pitch;
  const recess = [block(-2.7, 2.7, -0.45, 0.45, -1, 1.7), block(-0.45, 0.45, -2.7, 2.7, -1, 1.7)]; // cross drive
  const blank = lathe([[0, 0], [SCREW.head / 2, 0], [crest, headDepth], [crest, threadStart], [THREAD.root, threadStart], [THREAD.root, tipStart], [0, SCREW.length]]);
  const screw = own(compound([own(unwrap(cutAll(blank, recess))), helixTooth(THREAD.root, crest, SCREW.pitch, threadStart + flank, tipStart - flank, 0)])) as Shape;

  // The hole that a screw forms in the wood: a bore with the mating tooth, half a pitch from the tooth of the screw.
  const bore = crest + THREAD.play;
  const pilot = lathe([[0, 0], [crest, 0], [crest, threadStart], [bore, threadStart], [bore, tipStart], [0, SCREW.length]]);
  const formed = (from: number, to: number): Shape => helixTooth(bore, THREAD.root + THREAD.play, SCREW.pitch, from, to, SCREW.pitch / 2);
  const inJamb = formed(threadStart + flank, WOOD.jamb); // the frame screws pass through the jamb into the post
  const inPost = formed(WOOD.jamb, tipStart - flank);
  const halved = (s: Shape): Shape => own(unwrap(cutAll(s, [block(-9, 0, -9, 9, 0, SCREW.length + 1)]))) as Shape; // in the section plane
  const cutJamb = section ? halved(inJamb) : inJamb;
  const cutPost = section ? halved(inPost) : inPost;
  // Both sides turn the screw frame so that its +X half is below the section plane.
  const driven = (s: Shape, side: 1 | -1, only?: number): Shape[] =>
    holes.flatMap(([y, z], i) => (only !== undefined && (i === 3) !== (only === 3) ? [] : [
      own(translate(own(rotate(side > 0 ? s : own(rotate(s, 180) as Shape), 90 * side, { axis: [0, 1, 0] })), [side * x0, y, z]) as Shape),
    ]));
  const teeth = (side: 1 | -1, lower: Shape, top: Shape): Shape[] => [...driven(lower, side, 0), ...driven(top, side, 3)];

  // Door and frame. The leaf sits in a mortise as deep as the gauge. The pin stands clear of the door face.
  const face = DOOR.thickness - DOOR.backset - half; // y of the door face on the pin side
  const back = face - DOOR.thickness;
  const zb = -WOOD.margin;
  const zt = section ? HOLES.along[3]! : HEIGHT + WOOD.margin;
  const mortise = (side: 1 | -1): Shape => (side > 0 ? block(x0 - 1, x1, -half, face + 1, 0, HEIGHT) : block(-x1, 1 - x0, -half, face + 1, 0, HEIGHT));
  const wood = (s: Shape, side: 1 | -1): Shape => own(unwrap(cutAll(s, [mortise(side), ...driven(pilot, side)]))) as Shape;
  const door = wood(block(-x0 - WOOD.door, -x0, back, face, zb, zt), -1);
  const jamb = wood(block(x0, x0 + WOOD.jamb, face - WOOD.jambWidth, face, zb, zt), 1);
  const stop = block(x0 - WOOD.stop.thick, x0, back - 1 - WOOD.stop.width, back - 1, zb, zt);
  const post = wood(block(x0 + WOOD.jamb, x0 + WOOD.jamb + WOOD.post, face - WOOD.jambWidth, face, zb, zt), 1);

  // The door side turns about the pin. Then the whole model turns so that the open side faces +X.
  const view = swing >= 60 ? 270 - swing / 2 : 90;
  const fixed = (shapes: Shape[]): Shape => rotate(own(compound(shapes)), -view) as Shape;
  const moving = (shapes: Shape[]): Shape => rotate(own(compound(shapes)), -swing - view) as Shape;
  return {
    frameLeaf: fixed([leaf(1, [0, 2, 4])]),
    doorLeaf: moving([leaf(-1, [1, 3])]),
    pin: fixed([pin]),
    screws: screws ? [fixed(driven(screw, 1)), moving(driven(screw, -1))] : [],
    door: context ? [moving([door, ...teeth(-1, inJamb, cutJamb), ...teeth(-1, inPost, cutPost)])] : [],
    frame: context ? [fixed([jamb, stop, ...teeth(1, inJamb, cutJamb)])] : [],
    post: context ? [fixed([post, ...teeth(1, inPost, cutPost)])] : [],
  };
}

const part = freeing(() => hinge());

export default [
  color(part.frameLeaf, '#d3a956'),
  color(part.doorLeaf, '#d3a956'),
  color(part.pin, '#c3c9d1'),
  ...part.screws.map((s) => color(s, '#8b6a2c')),
  ...part.door.map((s) => color(s, '#12b5b0')),
  ...part.frame.map((s) => color(s, '#f5f2ea')),
  ...part.post.map((s) => color(s, '#c9a27a')),
];

Functions used ​

box compound cone cutAll cylinder extrude fuseAll line loft polygon revolve rotate translate unwrap wire color

▶ Run Butt Hinge on a Door in the playground

Released under the Apache 2.0 License.