Skip to content

Commit 07f4e22

Browse files
committed
Merge PR #66 from 'thehans/master' into master
2 parents 59d9752 + e083023 commit 07f4e22

1 file changed

Lines changed: 29 additions & 26 deletions

File tree

boxes.scad

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,43 @@
44
// Copyright: 2010
55
// License: 2-clause BSD License (http://opensource.org/licenses/BSD-2-Clause)
66

7-
// roundedBox([width, height, depth], float radius, bool sidesonly);
7+
//
8+
// roundedCube([x, y, z], r, sidesonly=true/false, center=true/false);
9+
// roundedCube(x, r, sidesonly=true/false, center=true/false);
810

911
// EXAMPLE USAGE:
10-
// roundedBox([20, 30, 40], 5, true);
12+
// roundedCube([20, 30, 40], 5, true, true);
1113

12-
// size is a vector [w, h, d]
14+
// Only for backwards compatibility with existing scripts, (always centered, radius instead of consistent "r" naming.
1315
module roundedBox(size, radius, sidesonly)
1416
{
15-
rot = [ [0,0,0], [90,0,90], [90,90,0] ];
16-
if (sidesonly) {
17-
cube(size - [2*radius,0,0], true);
18-
cube(size - [0,2*radius,0], true);
19-
for (x = [radius-size[0]/2, -radius+size[0]/2],
20-
y = [radius-size[1]/2, -radius+size[1]/2]) {
21-
translate([x,y,0]) cylinder(r=radius, h=size[2], center=true);
22-
}
23-
}
24-
else {
25-
cube([size[0], size[1]-radius*2, size[2]-radius*2], center=true);
26-
cube([size[0]-radius*2, size[1], size[2]-radius*2], center=true);
27-
cube([size[0]-radius*2, size[1]-radius*2, size[2]], center=true);
17+
echo("WARNING: roundedBox(size, radius, sidesonly) is deprecated, use roundedCube(size, r, sidesonly, center)");
18+
roundedCube(size, radius, sidesonly, true);
19+
}
2820

29-
for (axis = [0:2]) {
30-
for (x = [radius-size[axis]/2, -radius+size[axis]/2],
31-
y = [radius-size[(axis+1)%3]/2, -radius+size[(axis+1)%3]/2]) {
32-
rotate(rot[axis])
33-
translate([x,y,0])
34-
cylinder(h=size[(axis+2)%3]-2*radius, r=radius, center=true);
21+
// New implementation
22+
module roundedCube(size, r, sidesonly, center) {
23+
s = is_list(size) ? size : [size,size,size];
24+
translate(center ? -s/2 : [0,0,0]) {
25+
if (sidesonly) {
26+
hull() {
27+
translate([ r, r]) cylinder(r=r, h=s[2]);
28+
translate([ r,s[1]-r]) cylinder(r=r, h=s[2]);
29+
translate([s[0]-r, r]) cylinder(r=r, h=s[2]);
30+
translate([s[0]-r,s[1]-r]) cylinder(r=r, h=s[2]);
3531
}
3632
}
37-
for (x = [radius-size[0]/2, -radius+size[0]/2],
38-
y = [radius-size[1]/2, -radius+size[1]/2],
39-
z = [radius-size[2]/2, -radius+size[2]/2]) {
40-
translate([x,y,z]) sphere(radius);
33+
else {
34+
hull() {
35+
translate([ r, r, r]) sphere(r=r);
36+
translate([ r, r,s[2]-r]) sphere(r=r);
37+
translate([ r,s[1]-r, r]) sphere(r=r);
38+
translate([ r,s[1]-r,s[2]-r]) sphere(r=r);
39+
translate([s[0]-r, r, r]) sphere(r=r);
40+
translate([s[0]-r, r,s[2]-r]) sphere(r=r);
41+
translate([s[0]-r,s[1]-r, r]) sphere(r=r);
42+
translate([s[0]-r,s[1]-r,s[2]-r]) sphere(r=r);
43+
}
4144
}
4245
}
4346
}

0 commit comments

Comments
 (0)