Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module roundedcube_simple(size = [1, 1, 1], center = false, radius = 0.5) {
// If single value, convert to [x, y, z] vector
size = (size[0] == undef) ? [size, size, size] : size;
translate = (center == false) ?
[radius, radius, radius] :
[
radius - (size[0] / 2),
radius - (size[1] / 2),
radius - (size[2] / 2)
];
translate(v = translate)
minkowski() {
cube(size = [
size[0] - (radius * 2),
size[1] - (radius * 2),
size[2] - (radius * 2)
]);
sphere(r = radius);
}
}
@groovenectar

This comment has been minimized.

Copy link
Owner Author

commented Jul 23, 2015

Usage:

// A single integer creates a cube with the specified wall distance. Default [1, 1, 1]
size = 5;

// An [x, y, z] vector specifies distance on each axis. Default [1, 1, 1]
size = [2, 3, 5];

// Whether or not to place the object centered on the origin. Default false
center = true|false;

roundedcube_simple(size, center);

Examples:

color("Yellow")
roundedcube_simple(3, true, 0.9);

translate(v = [1, 0, 2])
color("Pink")
roundedcube_simple([4, 2, 2], false, 0.2);

translate(v = [-4, -1, 2])
color("Lightblue")
roundedcube_simple(2, false);

translate(v = [0, 0, 6])
color("Orange")
roundedcube_simple([3, 2, 2], true);

translate(v = [2.5, -0.5, 5])
color("Green")
roundedcube_simple([3, 2, 2], false, 0.09);

Output:

Output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.