Skip to content

V-Groove Slider Rail and Carriage ​

V-Groove Slider Rail and Carriage, rendered in the brepjs playground
Mechanical · 186 lines▶ Run it in the playground

A 20 x 20 slotted rail with a carriage on four V-wheels, one wheel in cutaway. The rail size and mass, the wheel, the 625 bearings, the eccentric spacers, the plate size and the M5 thread are published figures. Each M5 screw is a true helix in the mating thread of its lock nut. The kernel measures the rail mass for each metre from its section. The inside of the slots, the wheel tip, the ball sets and the hole pattern are a display model.

Code ​

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

ts
import { compound, cut, cutAll, cylinder, extrude, face, fuse, line, loft, measureVolume, polygon, revolve, rotate, sphere, threePointArc, translate, unwrap, wire } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// V-groove slider: a 20 x 20 slotted rail and a carriage on four V-wheels. The rail is on Y, the units are millimetres.
// The rail size and mass, the wheel, the 625 bearing, the eccentric spacer, the plate size and the M5 thread are published figures.
// The inside of the slots, the wheel tip, the ball sets and the hole pattern are a display model.
interface SliderParams {
  travel?: number; // position of the carriage along the rail, -20 to 20
  eccentric?: number; // degrees of the two eccentric spacers: 0 puts the wheels on the rail, 180 backs them off
  cutaway?: boolean; // open one wheel and take the plate off the two wheels on +X
}

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 RAIL = { size: 20, slot: 6, hole: 4.2, kgPerMetre: 0.429 };
const WHEEL = { outside: 23.9, width: 10.23, bore: 16 };
const BEARING = { bore: 5, outside: 16, width: 5 }; // 625
const SHIM = 1;
const SPACER = { height: 6, hex: 8, rim: 7.12, travel: 0.79 }; // eccentric spacer; the plain spacer has the same height
const PLATE = { size: 65, height: 3 };
const SCREW = { thread: 5, minor: 4.134, pitch: 0.8, length: 25 }; // M5 low-profile screw, metric coarse thread to the head
const NUT = { flats: 8, height: 5 }; // M5 lock nut
const DENSITY = 2.7e-3; // aluminium, grams per cubic millimetre

// ---- display model
const SLOT = { mouth: 9.16, lip: 1.8, cavity: 11, shelf: 6.4, core: 3.6, corner: 0.5 }; // slot section of the rail
const TIP = 5; // flat on the wheel between its two 45 degree flanks
const BALLS = { count: 7, diameter: 2.38, pitch: 5.25 };
const LENGTH = 110;
const WHEELBASE = 40; // wheel spacing along the rail
const HEAD = { radius: 4.6, height: 1.5, socket: 3 };
const PLAY = 0.1; // radial play between the screw thread and the nut thread

const Z: P3 = [0, 0, 1];
const lathe = (pts: P2[], angle = 2 * Math.PI): Shape => {
  const profile = own(unwrap(polygon(pts.map(([r, z]): P3 => [r, 0, z]))));
  return unwrap(revolve(profile, { axis: Z, angle })) as Shape;
};
const hexagon = (flats: number, z: number): P3[] => Array.from({ length: 6 }, (_, i): P3 => [(flats / Math.sqrt(3)) * Math.cos((i * Math.PI) / 3), (flats / Math.sqrt(3)) * Math.sin((i * Math.PI) / 3), z]);
const prism = (pts: P3[], height: number): Shape => own(unwrap(extrude(own(unwrap(polygon(pts))), [0, 0, height])) as Shape);
const move = (s: Shape, by: P3): Shape => own(translate(s, by) 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. hand 1 is a right-hand thread.
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, hand: 1 | -1 = 1): 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 = hand * 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 slider({ travel = 0, eccentric = 0, cutaway = true }: SliderParams = {}) {
  const h = RAIL.size / 2;
  const hb = BEARING.width + SHIM / 2; // bearings reach this far from the wheel centre
  const rw = WHEEL.outside / 2;
  const hw = WHEEL.width / 2;

  // Rail section: four slots with 45 degree mouths, a core with a centre hole, and a web to each corner.
  const m = SLOT.mouth / 2;
  const n = RAIL.slot / 2;
  const c = SLOT.cavity / 2;
  const top: P2[] = [
    [h - SLOT.corner, h], [m, h], [n, h - (m - n)], [n, h - SLOT.lip], [c, h - SLOT.lip], [c, SLOT.shelf], [c - (SLOT.shelf - SLOT.core), SLOT.core],
    [-c + (SLOT.shelf - SLOT.core), SLOT.core], [-c, SLOT.shelf], [-c, h - SLOT.lip], [-n, h - SLOT.lip], [-n, h - (m - n)], [-m, h], [-h + SLOT.corner, h],
  ];
  const ring = [0, 1, 2, 3].flatMap((k) => top.map(([x, y]): P2 => (k === 0 ? [x, y] : k === 1 ? [-y, x] : k === 2 ? [-x, -y] : [y, -x])));
  const upright = (pts: P2[]): P3[] => pts.map(([x, z]): P3 => [x, -LENGTH / 2, z + h]); // the section stands in the XZ plane
  const outline = own(unwrap(wire(upright(ring).map((p, i, all) => own(line(p, all[(i + 1) % all.length]!))))));
  const r = RAIL.hole / 2;
  const hole = own(unwrap(wire([own(threePointArc(upright([[r, 0]])[0]!, upright([[0, r]])[0]!, upright([[-r, 0]])[0]!)), own(threePointArc(upright([[-r, 0]])[0]!, upright([[0, -r]])[0]!, upright([[r, 0]])[0]!))])));
  const rail = unwrap(extrude(own(unwrap(face(outline as never, [hole as never]))), [0, LENGTH, 0])) as Shape;
  const kgPerMetre = (unwrap(measureVolume(rail)) / LENGTH) * DENSITY;

  // A wheel flank lies on a slot mouth. That sets the distance from the rail face to the wheel axis.
  const reach = rw - m + TIP / 2;
  const axis = h + reach;

  // One wheel about the origin: tyre, two bearings with a shim between them, and their balls.
  const tyre = own(lathe([
    [WHEEL.bore / 2, SHIM / 2], [WHEEL.bore / 2 - 1, SHIM / 2], [WHEEL.bore / 2 - 1, -SHIM / 2], [WHEEL.bore / 2, -SHIM / 2], [WHEEL.bore / 2, -hw],
    [rw - (hw - TIP / 2), -hw], [rw, -TIP / 2], [rw, TIP / 2], [rw - (hw - TIP / 2), hw], [WHEEL.bore / 2, hw],
  ]));
  const rb = BALLS.diameter / 2;
  const races = [SHIM / 2, -hb].flatMap((z) => [
    own(lathe([[BEARING.bore / 2, z], [BALLS.pitch - rb, z], [BALLS.pitch - rb, z + BEARING.width], [BEARING.bore / 2, z + BEARING.width]])),
    own(lathe([[BALLS.pitch + rb, z], [BEARING.outside / 2, z], [BEARING.outside / 2, z + BEARING.width], [BALLS.pitch + rb, z + BEARING.width]])),
  ]);
  const shim = own(lathe([[BEARING.bore / 2, -SHIM / 2], [BEARING.bore / 2 + 1.1, -SHIM / 2], [BEARING.bore / 2 + 1.1, SHIM / 2], [BEARING.bore / 2, SHIM / 2]]));
  const ballAt = (i: number, z: number): P3 => {
    const a = Math.PI / 2 + (2 * Math.PI * i) / BALLS.count;
    return [BALLS.pitch * Math.cos(a), BALLS.pitch * Math.sin(a), z];
  };
  const ballSet = (keep: number): Shape[] =>
    [SHIM / 2 + BEARING.width / 2, -SHIM / 2 - BEARING.width / 2].flatMap((z) => Array.from({ length: keep }, (_, i) => own(sphere(rb, { at: ballAt(i, z) }))));
  // The open wheel loses the half on +X. The balls on that side go with it.
  const half = own(rotate(own(lathe([[0, -hb - 1], [rw + 1, -hb - 1], [rw + 1, hb + 1], [0, hb + 1]], Math.PI)), -90, { axis: Z }) as Shape);
  const halved = (s: Shape): Shape => own(unwrap(cut(s, half)) as Shape);

  // Screw, lock nut and the two kinds of spacer. The stack hangs from the plate.
  // The screw has one helical tooth. The nut has the mating tooth, half a pitch away.
  const under = hb + SPACER.height; // plate underside above the wheel centre
  const head = under + PLATE.height;
  const tail = head - SCREW.length;
  const core = SCREW.minor / 2;
  const flank = 0.42 * SCREW.pitch;
  const blank = own(lathe([
    [0, tail], [core - 0.3, tail], [core, tail + 0.3], [core, head - 1], [SCREW.thread / 2, head - 1], [SCREW.thread / 2, head],
    [HEAD.radius, head], [HEAD.radius, head + HEAD.height - 0.5], [HEAD.radius - 0.5, head + HEAD.height], [0, head + HEAD.height],
  ]));
  const socketed = own(unwrap(cut(blank, prism(hexagon(HEAD.socket, head + HEAD.height - 1), 2))) as Shape);
  const screw = own(compound([socketed, helixTooth(core, SCREW.thread / 2, SCREW.pitch, tail + 0.3 + flank, head - 1 - flank, 0)]) as Shape);
  const hexNut = own(unwrap(cut(prism(hexagon(NUT.flats, -hb - NUT.height), NUT.height), own(cylinder(SCREW.thread / 2 + PLAY, NUT.height + 2, { at: [0, 0, -hb - NUT.height - 1] })))) as Shape);
  const nut = own(compound([hexNut, helixTooth(SCREW.thread / 2 + PLAY, core + PLAY, SCREW.pitch, -hb - NUT.height + flank, -hb - flank, SCREW.pitch / 2)]) as Shape);
  const plain = own(lathe([[SCREW.thread / 2, hb], [5, hb], [5, under], [SCREW.thread / 2, under]]));
  // Eccentric spacer: the hexagon and the rim are on the plate hole. The screw hole is off centre by half the travel.
  const e = SPACER.travel / 2;
  const body = own(unwrap(fuse(prism(hexagon(SPACER.hex, hb), SPACER.height), own(cylinder(SPACER.rim / 2, PLATE.height - 0.5, { at: [0, 0, under] })))) as Shape);
  const cam = own(rotate(own(unwrap(cut(body, own(cylinder(SCREW.thread / 2, 12, { at: [-e, 0, hb - 1] })))) as Shape), -eccentric, { axis: Z }) as Shape);
  const turn = (eccentric * Math.PI) / 180;
  const offset: P2 = [e - e * Math.cos(turn), e * Math.sin(turn)]; // wheel axis against its place on the rail

  // Four wheel stacks: plain spacers on -X, eccentric spacers on +X. The wheel at +X, -Y is the open one.
  const y0 = Math.min(20, Math.max(-20, travel));
  const tones = { tyre: [] as Shape[], steel: [] as Shape[], balls: [] as Shape[], cams: [] as Shape[], spacers: [] as Shape[] };
  const holes: Shape[] = [];
  for (const sx of [1, -1]) {
    for (const sy of [1, -1]) {
      const open = cutaway && sx > 0 && sy < 0;
      const at: P3 = [sx * axis + (sx > 0 ? offset[0] : 0), y0 + (sy * WHEELBASE) / 2 + (sx > 0 ? offset[1] : 0), h];
      const seat: P3 = sx > 0 ? [axis + e, y0 + (sy * WHEELBASE) / 2, h] : at; // centre of the plate hole
      tones.tyre.push(move(open ? halved(tyre) : tyre, at));
      tones.steel.push(...races.map((s) => move(open ? halved(s) : s, at)), move(open ? halved(shim) : shim, at), move(screw, at), move(nut, at));
      tones.balls.push(...ballSet(open ? 4 : BALLS.count).map((s) => move(s, at)));
      if (sx > 0) tones.cams.push(move(cam, seat));
      else tones.spacers.push(move(plain, at));
      holes.push(own(cylinder(sx > 0 ? SPACER.rim / 2 : SCREW.thread / 2 + 0.05, PLATE.height + 2, { at: [seat[0], seat[1], h + under - 1] })));
    }
  }

  // Plate: rounded corners, the four wheel holes and a grid of mounting holes. The cutaway takes the +X side off.
  const p = PLATE.size / 2;
  const k = 5;
  const slab = prism([[-p + k, -p, 0], [p - k, -p, 0], [p, -p + k, 0], [p, p - k, 0], [p - k, p, 0], [-p + k, p, 0], [-p, p - k, 0], [-p, -p + k, 0]], PLATE.height);
  const grid = [-10, 0, 10].flatMap((x) => [-20, 0, 20].map((y) => own(cylinder(2.55, PLATE.height + 2, { at: [x, y0 + y, h + under - 1] }))));
  const corner = cutaway ? [move(prism([[4, -p - 1, -1], [p + 1, -p - 1, -1], [p + 1, p + 1, -1], [4, p + 1, -1]], PLATE.height + 2), [0, y0, h + under])] : [];
  const plate = unwrap(cutAll(move(slab, [0, y0, h + under]), [...holes, ...grid, ...corner])) as Shape;

  const group = (shapes: Shape[]): Shape => compound(shapes) as Shape;
  return { rail, plate, tyre: group(tones.tyre), steel: group(tones.steel), balls: group(tones.balls), cams: group(tones.cams), spacers: group(tones.spacers), kgPerMetre, spacing: 2 * axis + offset[0] };
}

const part = freeing(() => slider());
console.log(
  'Rail: ' + part.kgPerMetre.toFixed(3) + ' kg/m from the kernel volume. The catalogue has ' + RAIL.kgPerMetre + ' kg/m. Wheel axes are ' + part.spacing.toFixed(2) + ' mm apart across the rail.',
);

export default [
  color(part.rail, '#c3c9d1'),
  color(part.plate, '#48515c'),
  color(part.tyre, '#12b5b0'),
  color(part.steel, '#a9b1ba'),
  color(part.balls, '#f2f4f7'),
  color(part.cams, '#ff5a1f'),
  color(part.spacers, '#f5f2ea'),
];

Functions used ​

compound cut cutAll cylinder extrude face fuse line loft measureVolume polygon revolve rotate sphere threePointArc translate unwrap wire color

▶ Run V-Groove Slider Rail and Carriage in the playground

Released under the Apache 2.0 License.