Created
February 17, 2020 05:56
-
-
Save tinkerology/ae257c5340a33ee2f149ff3ae97d9826 to your computer and use it in GitHub Desktop.
Create a cube with rounded sides
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$fn=60; | |
// Answer from: https://stackoverflow.com/users/1320888/cutetare | |
// https://stackoverflow.com/questions/33146741/way-to-round-edges-of-objects-openscad/33289349#33289349 | |
module roundedcube(xx, yy, height, radius) { | |
difference(){ | |
cube([xx,yy,height]); | |
difference(){ | |
translate([-.5,-.5,-.2]) | |
cube([radius+.5,radius+.5,height+.5]); | |
translate([radius,radius,height/2]) | |
cylinder(height,radius,radius,true); | |
} | |
translate([xx,0,0]) | |
rotate(90) | |
difference(){ | |
translate([-.5,-.5,-.2]) | |
cube([radius+.5,radius+.5,height+.5]); | |
translate([radius,radius,height/2]) | |
cylinder(height,radius,radius,true); | |
} | |
translate([xx,yy,0]) | |
rotate(180) | |
difference(){ | |
translate([-.5,-.5,-.2]) | |
cube([radius+.5,radius+.5,height+.5]); | |
translate([radius,radius,height/2]) | |
cylinder(height,radius,radius,true); | |
} | |
translate([0,yy,0]) | |
rotate(270) | |
difference(){ | |
translate([-.5,-.5,-.2]) | |
cube([radius+.5,radius+.5,height+.5]); | |
translate([radius,radius,height/2]) | |
cylinder(height,radius,radius,true); | |
} | |
} | |
} | |
// Simpler code with same result | |
module roundedcube2(xx, yy, height, radius) | |
{ | |
translate([0,0,height/2]) | |
hull() | |
{ | |
translate([radius,radius,0]) | |
cylinder(height,radius,radius,true); | |
translate([xx-radius,radius,0]) | |
cylinder(height,radius,radius,true); | |
translate([xx-radius,yy-radius,0]) | |
cylinder(height,radius,radius,true); | |
translate([radius,yy-radius,0]) | |
cylinder(height,radius,radius,true); | |
} | |
} | |
roundedcube(20, 30, 50, 5); | |
translate([30,0,0]) | |
roundedcube2(20, 30, 50, 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's my suggestion to add the center feature that normal cube() has (Plus centerxy, since that seems to be needed often)