2010-08-26 04:04:17 -05:00
|
|
|
// Library: boxes.scad
|
|
|
|
// Version: 1.0
|
|
|
|
// Author: Marius Kintel
|
|
|
|
// Copyright: 2010
|
2013-11-04 19:39:29 -06:00
|
|
|
// License: 2-clause BSD License (http://opensource.org/licenses/BSD-2-Clause)
|
2010-08-26 04:04:17 -05:00
|
|
|
|
2019-11-10 18:37:57 -06:00
|
|
|
//
|
|
|
|
// roundedCube([x, y, z], r, sidesonly=true/false, center=true/false);
|
|
|
|
// roundedCube(x, r, sidesonly=true/false, center=true/false);
|
2010-08-26 04:04:17 -05:00
|
|
|
|
|
|
|
// EXAMPLE USAGE:
|
2019-11-10 18:37:57 -06:00
|
|
|
// roundedCube([20, 30, 40], 5, true, true);
|
2010-08-26 04:04:17 -05:00
|
|
|
|
2019-11-10 18:37:57 -06:00
|
|
|
// Only for backwards compatibility with existing scripts, (always centered, radius instead of consistent "r" naming.
|
2010-08-26 04:04:17 -05:00
|
|
|
module roundedBox(size, radius, sidesonly)
|
|
|
|
{
|
2019-11-10 18:37:57 -06:00
|
|
|
echo("WARNING: roundedBox(size, radius, sidesonly) is deprecated, use roundedCube(size, r, sidesonly, center)");
|
|
|
|
roundedCube(size, radius, sidesonly, true);
|
|
|
|
}
|
2010-08-26 04:04:17 -05:00
|
|
|
|
2019-11-10 18:37:57 -06:00
|
|
|
// New implementation
|
|
|
|
module roundedCube(size, r, sidesonly, center) {
|
|
|
|
s = is_list(size) ? size : [size,size,size];
|
|
|
|
translate(center ? -s/2 : [0,0,0]) {
|
|
|
|
if (sidesonly) {
|
|
|
|
hull() {
|
|
|
|
translate([ r, r]) cylinder(r=r, h=s[2]);
|
|
|
|
translate([ r,s[1]-r]) cylinder(r=r, h=s[2]);
|
|
|
|
translate([s[0]-r, r]) cylinder(r=r, h=s[2]);
|
|
|
|
translate([s[0]-r,s[1]-r]) cylinder(r=r, h=s[2]);
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 18:37:57 -06:00
|
|
|
else {
|
|
|
|
hull() {
|
|
|
|
translate([ r, r, r]) sphere(r=r);
|
|
|
|
translate([ r, r,s[2]-r]) sphere(r=r);
|
|
|
|
translate([ r,s[1]-r, r]) sphere(r=r);
|
|
|
|
translate([ r,s[1]-r,s[2]-r]) sphere(r=r);
|
|
|
|
translate([s[0]-r, r, r]) sphere(r=r);
|
|
|
|
translate([s[0]-r, r,s[2]-r]) sphere(r=r);
|
|
|
|
translate([s[0]-r,s[1]-r, r]) sphere(r=r);
|
|
|
|
translate([s[0]-r,s[1]-r,s[2]-r]) sphere(r=r);
|
|
|
|
}
|
2010-08-26 04:04:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|