Tuesday, July 19, 2016

Create a Rounded Cube in OpenSCAD


There are two ways to easily make a rounded cube. The first is to use the hull function:

module RoundedCube(size, radius) {
    width = size[0];
    height = size[1];
    depth = size[2];
    
    hull() {
        translate([radius, radius, 0]) cylinder(r = radius, h = depth);
        translate([width - radius, radius, 0]) cylinder(r = radius, h = depth);
        translate([radius, height - radius, 0]) cylinder(r = radius, h = depth);
        translate([width - radius, height - radius, 0]) cylinder(r = radius, h = depth);
    }
}

The second is to use linear_extrude and the offset functions:

module RoundedCube(size, radius) {
    width = size[0];
    height = size[1];
    depth = size[2];

    translate([radius, radius, 0]) linear_extrude(height = depth) offset(r = radius) square([width, height]);
}

Now they aren't exactly identical. They will produce slightly different rounded cubes, but hopefully this helps someone out there use OpenSCAD.

No comments:

Post a Comment