example022.scad 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. // size is a vector [w, h, d]
  2. module roundedBox(size, radius, sidesonly)
  3. {
  4. rot = [ [0,0,0], [90,0,90], [90,90,0] ];
  5. if (sidesonly) {
  6. cube(size - [2*radius,0,0], true);
  7. cube(size - [0,2*radius,0], true);
  8. for (x = [radius-size[0]/2, -radius+size[0]/2],
  9. y = [radius-size[1]/2, -radius+size[1]/2]) {
  10. translate([x,y,0]) cylinder(r=radius, h=size[2], center=true);
  11. }
  12. }
  13. else {
  14. cube([size[0], size[1]-radius*2, size[2]-radius*2], center=true);
  15. cube([size[0]-radius*2, size[1], size[2]-radius*2], center=true);
  16. cube([size[0]-radius*2, size[1]-radius*2, size[2]], center=true);
  17. for (axis = [0:2]) {
  18. for (x = [radius-size[axis]/2, -radius+size[axis]/2],
  19. y = [radius-size[(axis+1)%3]/2, -radius+size[(axis+1)%3]/2]) {
  20. rotate(rot[axis])
  21. translate([x,y,0])
  22. cylinder(h=size[(axis+2)%3]-2*radius, r=radius, center=true);
  23. }
  24. }
  25. for (x = [radius-size[0]/2, -radius+size[0]/2],
  26. y = [radius-size[1]/2, -radius+size[1]/2],
  27. z = [radius-size[2]/2, -radius+size[2]/2]) {
  28. translate([x,y,z]) sphere(radius);
  29. }
  30. }
  31. }
  32. translate([-15,0,0])roundedBox([20,30,40], 5, true);
  33. translate([15,0,0]) roundedBox([20,30,40], 5, false);