Skip to content

Instantly share code, notes, and snippets.

@jmbarbier
Last active October 6, 2023 04:58
Show Gist options
  • Save jmbarbier/1a89f510e2103e21df42d5d75767d1b7 to your computer and use it in GitHub Desktop.
Save jmbarbier/1a89f510e2103e21df42d5d75767d1b7 to your computer and use it in GitHub Desktop.
Cubique simple jscad
// Cubique simple
const jscad = require('@jscad/modeling')
const {cube, sphere} = jscad.primitives
const {translate} = jscad.transforms
const {union, intersect} = jscad.booleans
const getParameterDefinitions = () => {
return [
{ name: 'a', type: 'int', initial: 200, caption: 'Parametre de maille (2R) en 1/10 mm ?' },
{ name: 'recouvrement', type: 'int', initial: 10, caption: 'Recouvrement en 1/10 de mm ?' },
{ name: 'qualite', type:'int', initial: 15, caption: 'Qualité des faces ?' }
];
}
const main = (params) => {
const a = params.a/10; // Paramètre de maille
const m = params.recouvrement/10; // Marge
const R =a/2+m/2;
const sph = {radius: R+m, segments: params.qualite};
const balls = union(
translate([0,0,0], sphere(sph)),
translate([a,0,0], sphere(sph)),
translate([0,a,0], sphere(sph)),
translate([a,a,0], sphere(sph)),
translate([0,0,a], sphere(sph)),
translate([a,0,a], sphere(sph)),
translate([0,a,a], sphere(sph)),
translate([a,a,a], sphere(sph)));
const full = intersect(
cube({center: [a/2,a/2,a/2], size: a}), balls)
return intersect(
cube({center: [a/2,a/2,0], size: a}),
full)
}
module.exports = {main, getParameterDefinitions }
@jmbarbier
Copy link
Author

image

@jmbarbier
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment