Skip to content

Dovetailed Drawer ​

Dovetailed Drawer, rendered in the brepjs playground
Mechanical · 117 lines▶ Run it in the playground

A small drawer with a through-dovetail joint on each corner: the sides carry the tails, the front and the back carry the pins. The slope follows the published rule, 1:6 for softwood and 1:8 for hardwood. The kernel measures the gap in a closed corner from the volumes of the two boards. The drawer size, the board thicknesses, the bottom panel and the pull are a display model.

Code ​

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

ts
import { box, compound, cutAll, cylinder, extrude, fuseAll, measureVolume, polygon, rotate, translate, unwrap } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// Through-dovetail joints on a small drawer. The sides carry the tails, the front and the back carry the pins.
// The slope ratios are the published rule: 1:6 for softwood and 1:8 for hardwood.
// The drawer size, the board thicknesses, the bottom panel and the pull are a display model. Units are millimetres.
interface DovetailParams {
  slope?: 6 | 8; // run for each unit of rise: 6 for softwood, 8 for hardwood
  tails?: number; // tails on each corner, 2 to 5
  explode?: number; // 0 = closed joint, 1 = the near side pulled off its pins
}

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 SLOPE = { softwood: 6, hardwood: 8 } as const; // 1:6 and 1:8

// ---- display model
const DRAWER = { depth: 260, width: 220, height: 96 }; // along X, Y and Z
const FRONT = 19; // thickness of the front and the back, the pin boards
const SIDE = 12.7; // thickness of the sides, the tail boards
const PIN = 6; // narrow end of a pin
const BOTTOM = { thick: 6, groove: 6, up: 10 }; // panel in a stopped groove
const PULL = { centres: 96, post: 5, stand: 22, bar: 5 };

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 outline in the XZ plane at y0, extruded to y1.
const slab = (pts: P2[], y0: number, y1: number): Shape => {
  const outline = own(unwrap(polygon(pts.map(([x, z]): P3 => [x, y0, z]))));
  return own(unwrap(extrude(outline, [0, y1 - y0, 0]))) as Shape;
};

function drawer({ slope = SLOPE.hardwood, tails = 3, explode = 0.7 }: DovetailParams = {}) {
  const n = Math.min(5, Math.max(2, Math.round(tails)));
  const pull = Math.min(1, Math.max(0, explode));
  const { depth, width, height } = DRAWER;
  const lean = FRONT / slope; // how far a tail flank moves over the thickness of the pin board
  const tail = (height - (n + 1) * PIN) / n; // wide end of a tail
  const foot = (i: number): number => PIN + i * (tail + PIN); // lower corner of tail i at the board end

  // Side: one outline with the tails at both ends. A tail is widest at the board end.
  const outline: P2[] = [[FRONT, 0], [depth - FRONT, 0]];
  for (let i = 0; i < n; i++) outline.push([depth - FRONT, foot(i) + lean], [depth, foot(i)], [depth, foot(i) + tail], [depth - FRONT, foot(i) + tail - lean]);
  outline.push([depth - FRONT, height], [FRONT, height]);
  for (let i = n - 1; i >= 0; i--) outline.push([FRONT, foot(i) + tail - lean], [0, foot(i) + tail], [0, foot(i)], [FRONT, foot(i) + lean]);
  const g = BOTTOM.groove;
  const z0 = BOTTOM.up;
  const z1 = z0 + BOTTOM.thick;
  const side = own(unwrap(cutAll(slab(outline, 0, SIDE), [block(FRONT, depth - FRONT, SIDE - g, SIDE + 1, z0, z1)]))) as Shape;

  // Front: a plain board with the pins on both ends. The pins fill the gaps between the tails.
  const pins = [0, width - SIDE].flatMap((y) =>
    Array.from({ length: n + 1 }, (_, j) => {
      const low = j === 0 ? 0 : foot(j - 1) + tail;
      const high = j === n ? height : foot(j);
      const a = j === 0 ? 0 : lean;
      const b = j === n ? 0 : lean;
      return slab([[0, low], [0, high], [FRONT, high + b], [FRONT, low - a]], y, y + SIDE);
    }),
  );
  const board = block(0, FRONT, SIDE, width - SIDE, 0, height);
  const front = own(unwrap(cutAll(own(unwrap(fuseAll([board, ...pins]))), [block(FRONT - g, FRONT + 1, SIDE, width - SIDE, z0, z1)]))) as Shape;

  // Bottom panel: it fills the four grooves. Its corners are cut back because the grooves stop at the joints.
  const xs = [FRONT - g, FRONT, depth - FRONT, depth - FRONT + g];
  const ys = [SIDE - g, SIDE, width - SIDE, width - SIDE + g];
  const ring: P2[] = [[1, 0], [2, 0], [2, 1], [3, 1], [3, 2], [2, 2], [2, 3], [1, 3], [1, 2], [0, 2], [0, 1], [1, 1]];
  const sheet = own(unwrap(polygon(ring.map(([i, j]): P3 => [xs[i]!, ys[j]!, z0]))));
  const panel = own(unwrap(extrude(sheet, [0, 0, BOTTOM.thick]))) as Shape;

  // Bar pull on the front: two posts and a bar.
  const mid = width / 2;
  const posts = [-1, 1].map((s) => own(cylinder(PULL.post, PULL.stand, { at: [-PULL.stand, mid + (s * PULL.centres) / 2, height / 2], axis: [1, 0, 0] })));
  const bar = own(cylinder(PULL.bar, PULL.centres + 24, { at: [-PULL.stand - PULL.bar, mid - PULL.centres / 2 - 12, height / 2], axis: [0, 1, 0] }));

  // The joint closes with no gap when the wood of one corner fills its whole block.
  const corner = block(0, FRONT, 0, SIDE, 0, height);
  const wood = [side, front].reduce((sum, s) => sum + unwrap(measureVolume(own(unwrap(cutAll(corner, [s]))) as Shape)), 0);
  const gap = FRONT * SIDE * height - wood;

  // The near side comes off along its tails. Then the model turns so that this side faces +X.
  const show = (shapes: Shape[], v: P3 = [0, 0, 0]): Shape => rotate(own(translate(own(compound(shapes)), v)), 90, { at: [depth / 2, width / 2, 0] }) as Shape;
  const back = own(rotate(front, 180, { at: [depth / 2, width / 2, 0] }) as Shape);
  return {
    near: show([side], [0, -pull * 70, 0]),
    far: show([own(rotate(side, 180, { at: [depth / 2, width / 2, 0] }) as Shape)]),
    ends: show([front, back]),
    panel: show([panel]),
    pull: show([...posts, bar]),
    gap,
    angle: (Math.atan(1 / slope) * 180) / Math.PI,
    slope,
  };
}

const part = freeing(() => drawer());
console.log('Slope 1:' + part.slope + ' is ' + part.angle.toFixed(1) + ' degrees. Gap in a closed corner, from the kernel volumes: ' + Math.abs(part.gap).toFixed(2) + ' mm3.');

export default [
  color(part.near, '#e3c79a'),
  color(part.far, '#e3c79a'),
  color(part.ends, '#7a4a2b'),
  color(part.panel, '#c9a27a'),
  color(part.pull, '#d3a956'),
];

Functions used ​

box compound cutAll cylinder extrude fuseAll measureVolume polygon rotate translate unwrap color

▶ Run Dovetailed Drawer in the playground

Released under the Apache 2.0 License.