Merge PR #66 from 'thehans/master' into master
This commit is contained in:
commit
07f4e22a25
55
boxes.scad
55
boxes.scad
|
@ -4,40 +4,43 @@
|
||||||
// Copyright: 2010
|
// Copyright: 2010
|
||||||
// License: 2-clause BSD License (http://opensource.org/licenses/BSD-2-Clause)
|
// License: 2-clause BSD License (http://opensource.org/licenses/BSD-2-Clause)
|
||||||
|
|
||||||
// roundedBox([width, height, depth], float radius, bool sidesonly);
|
//
|
||||||
|
// roundedCube([x, y, z], r, sidesonly=true/false, center=true/false);
|
||||||
|
// roundedCube(x, r, sidesonly=true/false, center=true/false);
|
||||||
|
|
||||||
// EXAMPLE USAGE:
|
// EXAMPLE USAGE:
|
||||||
// roundedBox([20, 30, 40], 5, true);
|
// roundedCube([20, 30, 40], 5, true, true);
|
||||||
|
|
||||||
// size is a vector [w, h, d]
|
// Only for backwards compatibility with existing scripts, (always centered, radius instead of consistent "r" naming.
|
||||||
module roundedBox(size, radius, sidesonly)
|
module roundedBox(size, radius, sidesonly)
|
||||||
{
|
{
|
||||||
rot = [ [0,0,0], [90,0,90], [90,90,0] ];
|
echo("WARNING: roundedBox(size, radius, sidesonly) is deprecated, use roundedCube(size, r, sidesonly, center)");
|
||||||
if (sidesonly) {
|
roundedCube(size, radius, sidesonly, true);
|
||||||
cube(size - [2*radius,0,0], true);
|
}
|
||||||
cube(size - [0,2*radius,0], true);
|
|
||||||
for (x = [radius-size[0]/2, -radius+size[0]/2],
|
|
||||||
y = [radius-size[1]/2, -radius+size[1]/2]) {
|
|
||||||
translate([x,y,0]) cylinder(r=radius, h=size[2], center=true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cube([size[0], size[1]-radius*2, size[2]-radius*2], center=true);
|
|
||||||
cube([size[0]-radius*2, size[1], size[2]-radius*2], center=true);
|
|
||||||
cube([size[0]-radius*2, size[1]-radius*2, size[2]], center=true);
|
|
||||||
|
|
||||||
for (axis = [0:2]) {
|
// New implementation
|
||||||
for (x = [radius-size[axis]/2, -radius+size[axis]/2],
|
module roundedCube(size, r, sidesonly, center) {
|
||||||
y = [radius-size[(axis+1)%3]/2, -radius+size[(axis+1)%3]/2]) {
|
s = is_list(size) ? size : [size,size,size];
|
||||||
rotate(rot[axis])
|
translate(center ? -s/2 : [0,0,0]) {
|
||||||
translate([x,y,0])
|
if (sidesonly) {
|
||||||
cylinder(h=size[(axis+2)%3]-2*radius, r=radius, center=true);
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (x = [radius-size[0]/2, -radius+size[0]/2],
|
else {
|
||||||
y = [radius-size[1]/2, -radius+size[1]/2],
|
hull() {
|
||||||
z = [radius-size[2]/2, -radius+size[2]/2]) {
|
translate([ r, r, r]) sphere(r=r);
|
||||||
translate([x,y,z]) sphere(radius);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue