Rounded Corners in OpenSCAD

roundedcube.scad

This OpenSCAD module allows you to create a cube object with rounded corners. The syntax is very similar to the native cube() primitive solid function syntax, so at the simplest level you can just switch out "cube" for "roundedcube".

It is compatible with the 2015+ builds of OpenSCAD. Older versions may or may not be compatible with the line that detects whether the size argument is likely an integer or [x, y, z] vector. That line can be removed, but then you would always need to pass a vector.

If you have ideas for optimizations or code improvements, please, fork the gist and push updates or Telegram me @supdanup with suggestions or comments :)

Download

Right-click and "Save As..." or click to view: roundedcube.scad (1.8 kB)

Usage

// An [x, y, z] vector specifies distance on each axis. Default [1, 1, 1] size = [2, 3, 5]; // An integer creates a cube with specified wall distance. Default [1, 1, 1] size = 5; // Whether or not to place the object centered on the origin. Default false center = true|false; // Specify a rounding radius. Default 0.5 radius = 0.5 // Specify where to apply the rounded corners. Default "all" apply_to = "all"|"x"|"y"|"z"|"zmax"|"zmin"|"xmax"|"xmin"|"ymax"|"ymin" roundedcube(size, center, radius, apply_to);

Examples and Output:

color("Yellow") roundedcube(3, true, 0.7, "xmin"); translate(v = [1, 0, 2]) color("Pink") roundedcube([4, 2, 2], false, 0.6, "zmax"); translate(v = [-4, -1, 2]) color("Lightblue") roundedcube(2, false); translate(v = [0, 0, 6]) color("Orange") roundedcube([3, 2, 2], true, 0.2); translate(v = [2.5, -0.5, 5]) color("Green") roundedcube([3, 2, 2], false, 0.4, "z");

Module Code

If you don't care about being able to apply the rounding to individual sides, and always want the whole box rounded, then you might be better off with roundedcube_simple.scad. It's generally faster than the roundedcube.scad module above, simplier, but less flexible.

Back to DanielUpshaw.com