Guest User

Untitled

a guest
Jan 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. ///
  2. /// OpenSCAD utils
  3. /// by Pat Niemeyer (pat@pat.net)
  4. ///
  5.  
  6. // Rounded cube fitting exactly inside a cube of the same dimensions.
  7. //
  8. // Demo roundedCube
  9. //%cube(size=[s,s,h], center=true);
  10. //roundedCube([s, s, h], 1, center=true);
  11. //%cube(size=[s,s,h], center=false);
  12. //roundedCube([s, s, h], 1, center=false);
  13. //
  14. module rounded_cube(size, radius, center=true)
  15. {
  16. width = size[0] - radius*2;
  17. length = size[1] - radius*2;
  18. height = size[2] - radius*2;
  19.  
  20. _translateIfNeeded(radius,center)
  21. minkowski() {
  22. cube(size=[width,length,height], center=center);
  23. sphere(r=radius, center=center);
  24. }
  25. }
  26.  
  27. module _translateIfNeeded(r, center) {
  28. if (center) {
  29. children();
  30. } else {
  31. translate([r,r,r]) children();
  32. }
  33. }
  34.  
  35. //
  36. // Minkowski helpers
  37. //
  38.  
  39. // Use minkowski to add radius r outside the children
  40. module round_outside(r=1.0) {
  41. minkowski() {
  42. children();
  43. sphere(r=r);
  44. }
  45. }
  46.  
  47. //
  48. // Translate helpers
  49. //
  50. module tx(x) { translate([x,0,0]) children(); }
  51. module ty(y) { translate([0,y,0]) children(); }
  52. module tz(z) { translate([0,0,z]) children(); }
  53. module rotx(x) { rotate([x,0,0]) children(); }
  54. module roty(y) { rotate([0,y,0]) children(); }
  55. module rotz(z) { rotate([0,0,z]) children(); }
  56.  
  57. //
  58. // Cut helpers
  59. //
  60.  
  61. // cut x "left/right"
  62. module cutx(x=0, keep="left", max=120) {
  63. difference() {
  64. children();
  65. if (keep=="left") {
  66. tx(x+max/2) cube([max,max,max], center=true);
  67. } else {
  68. tx(x-max/2) cube([max,max,max], center=true);
  69. }
  70. }
  71. }
  72.  
  73. // cut y "front/back"
  74. module cuty(y=0, keep="front", max=120) {
  75. difference() {
  76. children();
  77. if (keep=="front") {
  78. ty(y+max/2) cube([max,max,max], center=true);
  79. } else {
  80. ty(y-max/2) cube([max,max,max], center=true);
  81. }
  82. }
  83. }
  84.  
  85. // cut z "top/bottom"
  86. module cutz(z=0, keep="bottom", max=120) {
  87. difference() {
  88. children();
  89. if (keep=="bottom") {
  90. tz(z+max/2) cube([max,max,max], center=true);
  91. } else {
  92. tz(z-max/2) cube([max,max,max], center=true);
  93. }
  94. }
  95. }
Add Comment
Please, Sign In to add comment