Default (use_fillets=1):
For those that like boxes (use_fillets=0):
But yes, there is more (use_fillets=2):
The possibilities are sorted in the order of probablility of working well out-of-the-box, I have not tested the last variant at all yet.
module polyhole(d,h) { n = max(round(2 * d),3); rotate([0,0,180]) cylinder(h = h, r = (d / 2) / cos (180 / n), $fn = n); }
// make it interchangeable between this and cylinder module cylinder_poly(r, h, center=false){ polyhole(d=r*2, h=h, center=center); }
module fillet(radius, height=100, $fn=16) { //this creates negative of fillet, //i.e. thing to be substracted from object translate([-radius, -radius, -height/2-0.01]) difference() { cube([radius*2, radius*2, height+0.02]); cylinder(r=radius, h=height+0.02, $fn=16); } }
module cube_negative_fillet( size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0 ){ j=[1,0,1,0]; for (i=[0:3]) { if (radius > -1) { rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(radius, size[2], $fn=$fn); } else { rotate([0, 0, 90*i]) translate([size[1-j[i]]/2, size[j[i]]/2, 0]) fillet(vertical[i], size[2], $fn=$fn); } rotate([90*i, -90, 0]) translate([size[2]/2, size[j[i]]/2, 0 ]) fillet(top[i], size[1-j[i]], $fn=$fn); rotate([90*(4-i), 90, 0]) translate([size[2]/2, size[j[i]]/2, 0]) fillet(bottom[i], size[1-j[i]], $fn=$fn); } }
module cube_fillet_inside( size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], $fn=0 ){ if (radius == 0) { cube(size, center=true); } else { difference() { cube(size, center=true); cube_negative_fillet(size, radius, vertical, top, bottom, $fn); } } } module cube_fillet( size, radius=-1, vertical=[3,3,3,3], top=[0,0,0,0], bottom=[0,0,0,0], center=false, $fn=0 ){ if (center) { cube_fillet_inside(size, radius, vertical, top, bottom, $fn); } else { translate([size[0]/2, size[1]/2, size[2]/2]) cube_fillet_inside(size, radius, vertical, top, bottom, $fn); } }