← Back to projects
PROJECT / 05Personal lab
Parametric 3D printing part
An adjustable rectangular base with STL export.
WEB PROTOTYPE
Adjust width, depth and thickness. This creates a simple solid part in millimetres, with no holes or relief. Review the STL in your slicer before printing.
Schematic preview. The STL contains a closed solid box.
View concept code
export function boxSTL(w, d, h) {
if (![w, d, h].every((v) => Number.isFinite(v) && v > 0 && v <= 500))
throw Error('Invalid dimension');
const p = [
[0, 0, 0],
[w, 0, 0],
[w, d, 0],
[0, d, 0],
[0, 0, h],
[w, 0, h],
[w, d, h],
[0, d, h],
];
const faces = [
[0, 2, 1],
[0, 3, 2],
[4, 5, 6],
[4, 6, 7],
[0, 1, 5],
[0, 5, 4],
[1, 2, 6],
[1, 6, 5],
[2, 3, 7],
[2, 7, 6],
[3, 0, 4],
[3, 4, 7],
];
return (
'solid neoquarz_base\n' +
faces
.map((f) => {
const [a, b, c] = f.map((i) => p[i]);
const u = b.map((x, i) => x - a[i]),
v = c.map((x, i) => x - a[i]);
let n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]],
len = Math.hypot(...n);
n = n.map((x) => x / len);
return `facet normal ${n.join(' ')}\n outer loop\n${f.map((i) => ' vertex ' + p[i].join(' ')).join('\n')}\n endloop\nendfacet`;
})
.join('\n') +
'\nendsolid neoquarz_base\n'
);
}