Skip to content

Square Stage Truss ​

Square Stage Truss, rendered in the brepjs playground
Mechanical · 127 lines▶ Run it in the playground

A 0.5 m segment of a 290 mm square stage truss with its four conical couplers, pins and clips pulled out. The section, the 50 x 2 mm chords, the 16 x 2 mm braces, the alloy, the lengths and the masses are published figures. The kernel measures the chord section and the mass and prints them beside the catalogue values. The brace pattern, the receivers, the cones, the pins and the clips are a display model.

Code ​

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

ts
import { compound, cone, cutAll, cylinder, fuse, fuseAll, measureVolume, polygon, revolve, rotate, torus, translate, unwrap } from 'brepjs/quick';
import { color } from 'brepjs/playground';

// Square stage truss segment of the 290 mm class with its conical couplers. The truss runs along X, units are millimetres.
// The section, the tube sizes, the alloy, the lengths and the masses are published figures.
// The brace pattern, the receivers, the cones, the pins and the clips are a display model.
interface TrussParams {
  length?: 500 | 1000 | 2000 | 3000; // catalogue lengths
  explode?: number; // 0 = cones pinned in the receivers, 1 = cones, pins and clips pulled out
}

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 SIDE = 290; // outside to outside of the chords
const CHORD = { diameter: 50, wall: 2 };
const BRACE = { diameter: 16, wall: 2 };
const CHORD_AREA_CM2 = 12.06; // metal section of the four chords
const CATALOGUE_KG = { 500: 4.6, 1000: 7, 2000: 10, 3000: 15 }; // with four cones and their pins
const DENSITY = { aluminium: 2.7e-6, steel: 7.85e-6 }; // kilograms per cubic millimetre, EN AW-6082 and steel

// ---- display model
const END = 70; // first brace node from each end
const RECEIVER = { length: 55, socket: 45, mouth: 15, floor: 11.5 }; // turned end piece with a conical socket
const PIN = { big: 5, small: 3.8, length: 64, head: 4 }; // tapered pin, driven in from the outside
const CLIP = { wire: 1, loop: 4.5 };

const rod = (a: P3, b: P3, r: number): Shape => {
  const d: P3 = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
  const len = Math.hypot(d[0], d[1], d[2]);
  return own(cylinder(r, len, { at: a, axis: [d[0] / len, d[1] / len, d[2] / len] }));
};

// A closed [x, r] profile revolved about the X axis.
const lathe = (pts: P2[]): Shape => {
  const profile = own(unwrap(polygon(pts.map(([x, r]): P3 => [x, 0, r]))));
  return own(unwrap(revolve(profile, { axis: [1, 0, 0] }))) as Shape;
};

const volume = (s: Shape): number => unwrap(measureVolume(s));
const moved = (s: Shape, v: P3): Shape => own(translate(s, v) as Shape);

function truss({ length = 500, explode = 1 }: TrussParams = {}) {
  const pull = Math.min(1, Math.max(0, explode));
  const c = (SIDE - CHORD.diameter) / 2; // chord axis from the truss axis
  const corners: P2[] = [[c, c], [-c, c], [-c, -c], [c, -c]]; // [y, z]
  const at = (i: number, x: number): P3 => [x, corners[i % 4]![0], corners[i % 4]![1]];
  const rc = CHORD.diameter / 2;
  const rb = BRACE.diameter / 2;

  // Chords between the receivers, then the braces of the four sides: an end frame and a zig-zag.
  const x0 = RECEIVER.length;
  const x1 = length - RECEIVER.length;
  const tubes = corners.map((_, i) => rod(at(i, x0), at(i, x1), rc));
  const bores = corners.map((_, i) => rod(at(i, x0 - 1), at(i, x1 + 1), rc - CHORD.wall));
  const bays = Math.max(2, 2 * Math.round((length - 2 * END) / (4 * c)));
  const station = (k: number): number => END + (k * (length - 2 * END)) / bays;
  const lines: [P3, P3][] = [];
  for (let side = 0; side < 4; side++) {
    lines.push([at(side, station(0)), at(side + 1, station(0))], [at(side, station(bays)), at(side + 1, station(bays))]);
    for (let k = 0; k < bays; k++) {
      const flip = (k + side) % 2;
      lines.push([at(side + flip, station(k)), at(side + 1 - flip, station(k + 1))]);
    }
  }
  const braces = lines.map(([a, b]) => rod(a, b, rb));
  // The bore of a brace stops short of the chord, so the weld end stays closed.
  const hollows = lines.map(([a, b]) => {
    const t = 30 / (2 * c);
    const p = (s: number): P3 => [a[0] + (b[0] - a[0]) * s, a[1] + (b[1] - a[1]) * s, a[2] + (b[2] - a[2]) * s];
    return rod(p(t), p(1 - t), rb - BRACE.wall);
  });
  const weldment = unwrap(cutAll(own(unwrap(fuseAll([...tubes, ...braces]))), [...bores, ...hollows])) as Shape;

  // One receiver, one cone and one pin on the X axis, then copies on the four chords.
  const d = RECEIVER.socket;
  const pinX = -d / 2;
  const pinTool = (x: number): Shape => own(cone(PIN.big, PIN.small, PIN.length, { at: [x, PIN.length / 2, 0], axis: [0, -1, 0] }));
  const socket: P2[] = [[-RECEIVER.length, 0], [-RECEIVER.length, rc], [-3, rc], [0, rc - 3], [0, RECEIVER.mouth], [-d, RECEIVER.floor], [-d, 0]];
  const receiver = own(unwrap(cutAll(lathe(socket), [pinTool(pinX)]))) as Shape;
  const coneBlank = lathe([[-d, 0], [-d, RECEIVER.floor], [0, RECEIVER.mouth], [d, RECEIVER.floor], [d, 0]]);
  const coupler = own(unwrap(cutAll(coneBlank, [pinTool(pinX), pinTool(-pinX)]))) as Shape;
  const clipY = -PIN.length / 2 + 4; // the clip goes through the thin end of the pin
  const clipLeg = own(cylinder(CLIP.wire, 18, { at: [pinX - 9, clipY, 0], axis: [1, 0, 0] }));
  const pinBody = own(unwrap(fuse(pinTool(pinX), own(cylinder(PIN.big + 2, PIN.head, { at: [pinX, PIN.length / 2, 0], axis: [0, 1, 0] }))))) as Shape;
  const pin = own(unwrap(cutAll(pinBody, [clipLeg]))) as Shape;
  const loop = own(rotate(own(torus(CLIP.loop, CLIP.wire, { at: [pinX - 9 - CLIP.loop, clipY, 0] })), 90, { axis: [1, 0, 0], at: [pinX - 9 - CLIP.loop, clipY, 0] }) as Shape);
  const clip = own(unwrap(fuse(clipLeg, loop))) as Shape;

  // The thick end of each pin is on the outside of the truss: the parts on the -Y chords are turned over.
  const outward = (s: Shape, y: number): Shape => (y > 0 ? s : own(rotate(s, 180, { axis: [1, 0, 0] }) as Shape));
  const far = corners.map(([y, z]) => moved(outward(receiver, y), [length, y, z]));
  const near = corners.map(([y, z]) => moved(own(rotate(receiver, 180, { axis: [0, 0, 1] }) as Shape), [0, y, z]));
  const cones = corners.map(([y, z]) => moved(outward(coupler, y), [length + pull * 95, y, z]));
  const pins = corners.map(([y, z]) => moved(outward(pin, y), [length, y + Math.sign(y) * pull * 50, z]));
  const clips = corners.map(([y, z]) => moved(outward(clip, y), [length - pull * 16, y - Math.sign(y) * pull * 12, z + pull * 34]));

  // Mass and chord section from the kernel volumes.
  const sum = (shapes: Shape[]): number => shapes.reduce((total, s) => total + volume(s), 0);
  const kg = (volume(weldment) + sum(far) + sum(near) + sum(cones)) * DENSITY.aluminium + (sum(pins) + sum(clips)) * DENSITY.steel;
  const slice = own(unwrap(cutAll(own(cylinder(rc, 10)), [own(cylinder(rc - CHORD.wall, 12, { at: [0, 0, -1] }))]))) as Shape; // 10 mm of one chord
  const chordArea = (4 * volume(slice)) / 10 / 100;

  return { weldment, receivers: compound([...far, ...near]) as Shape, cones: compound(cones) as Shape, pins: compound(pins) as Shape, clips: compound(clips) as Shape, kg, chordArea, length };
}

const part = freeing(() => truss());
console.log('Mass: ' + part.kg.toFixed(2) + ' kg from the kernel volumes. The catalogue has ' + CATALOGUE_KG[part.length] + ' kg for ' + part.length / 1000 + ' m.');
console.log('Chord section: ' + part.chordArea.toFixed(2) + ' cm2 from the kernel. The catalogue has ' + CHORD_AREA_CM2 + ' cm2.');

export default [
  color(part.weldment, '#c3c9d1'),
  color(part.receivers, '#8d96a1'),
  color(part.cones, '#12b5b0'),
  color(part.pins, '#ff5a1f'),
  color(part.clips, '#48515c'),
];

Functions used ​

compound cone cutAll cylinder fuse fuseAll measureVolume polygon revolve rotate torus translate unwrap color

▶ Run Square Stage Truss in the playground

Released under the Apache 2.0 License.