# Round corners for Openscad - Tutorial

## by WilliamAAdams, published

## Description

This thing is a little bit of a tutorial on how to do rounded corners on things using the 'hull()' builtin module.

I derived from this other thing because although there is already a 'boxes.scad' that comes with the standard OpenScad, it shows that there's more than one way to skin a box.

The 'hull()' method basically fills out a convex hull based on the points that are layed out in 2D. In the case of a rectangle, you can essentially just place circles at the corners, and use the hull() with a linear_extrude(), and you've got your rounded rectangle thing.

module roundedRect(size, radius)

{

x = size[0];

y = size[1];

z = size[2];

linear_extrude(height=z)

hull()

{

// place 4 circles in the corners, with the given radius

translate([(-x/2)+(radius/2), (-y/2)+(radius/2), 0])

circle(r=radius);

translate([(x/2)-(radius/2), (-y/2)+(radius/2), 0])

circle(r=radius);

translate([(-x/2)+(radius/2), (y/2)-(radius/2), 0])

circle(r=radius);

translate([(x/2)-(radius/2), (y/2)-(radius/2), 0])

circle(r=radius);

}

}

It's as simple as that!

What I like about this is the flexibility. You're not limited to rectangles. You can layout as many little circles as you like, with any radius, and the hull() method will 'do the needful'.

Another way to do this is to use a hidden gem calls minkowski sum:

module miniround(size, radius)

{

$fn=50;

x = size[0]-radius/2;

y = size[1]-radius/2;

minkowski()

{

cube(size=[x,y,size[2]]);

cylinder(r=radius);

// Using a sphere is possible, but will kill performance

//sphere(r=radius);

}

}

If you use $fn=12, then you can use the sphere, and get rounded corners all around. Higher values will be more round, but will really take a long time to render.

Personally, I'm not totally clear on the limitations of using minkowski. Apparently, if you tried to the it this way:

module roundedPolygon(polypoints, paths, height, radius)

{

linear_extrude(height=height, convexity=3)

hull()

for(pt = polypoints)

{

translate([pt[0], pt[1], 0])

circle(r=radius);

}

}

You'd get an error related to minkowski.

At any rate, there are multiple ways to do things with OpenScad. Even though there are many libraries available, it might prove useful to explore the possibilities anyway as you might find another way that better suits your needs and situation.

## Recent Comments

view allI like this version better, it matches cube() better:

module roundedRect(size, radius) {

x = size[0];

y = size[1];

z = size[2];

linear_extrude(height=z)

hull() {

translate([radius, radius, 0])

circle(r=radius);

translate([x - radius, radius, 0])

circle(r=radius);

translate([x - radius, y - radius, 0])

circle(r=radius);

transla

te([radius, y - radius, 0])

circle(r=radius);

}

}

## Tags

## License

## Give a Shout Out

## Instructions

2) Play with it

3) Explore OpenScad to discover new gems

4) Rejoice!

## Comments

You must be logged in to post a comment.

Cool tutorial, thanks!

However, for your Minkowski example, I think you multiply the corner radius by 2, not divide, ie:

x = size[0]-radius*2;

y = size[1]-radius*2;

...if you want the x and y size you specify to correctly specify the outer dimensions of the final object.

Yah, I saw that after I posted.

Really, it's just

translate([(-x/2)+radius, (-y/2)+radius, 0])

One way you can do this in rapcad is using 3D convex hulls:

module rounded_cube(w,h,d,dia){

hull(){

sphere(d=dia);

translate([0,h,d])sphere(d=dia);

translate([w,0,d])sphere(d=dia);

translate([w,h,0])sphere(d=dia);

translate([w,h,d])sphere(d=dia);

translate([0,0,d])sphere(d=dia);

translate([w,0,0])sphere(d=dia);

translate([0,h,0])sphere(d=dia);

}

}

rounded_cube(10,10,10,5);

Nice approach - pity about the iterated version. Hope they enhance / fix that in future.

Btw, minkowski support for 2d objects and the hull function are both fairly recent additions to [email protected], so if these do not work for you, upgrade to a newer version.

I like this version better, it matches cube() better:

module roundedRect(size, radius) {

x = size[0];

y = size[1];

z = size[2];

linear_extrude(height=z)

hull() {

translate([radius, radius, 0])

circle(r=radius);

translate([x - radius, radius, 0])

circle(r=radius);

translate([x - radius, y - radius, 0])

circle(r=radius);

transla

te([radius, y - radius, 0])

circle(r=radius);

}

}