Loading

Round corners for Openscad - Library

by WarrantyVoider, published

Round corners for Openscad - Library by WarrantyVoider May 26, 2011

Contents

Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag

Thing Statistics

17084Views 3235Downloads

Summary

Making a cube in OpenScad takes just one line of code. Making it nicer (with rounded corners) takes... 40 lines of code!
But hey, the good thing about OpenScad is that once someone makes a library, everything becomes trivial.
So now, making tidy iPhonesque shapes requires just a line of code:
roundCornersCube(10,5,2,1);

Instructions

You have several options to use this library:
a) Open the .scad file, copy its content and paste it in your script
b) Include the file in your script with any of these commands:
include<"roundCornersCube.stl">
use<"roundCornersCube">
For this option, the library file should be in the same folder as your script.
c) Download the file and copy it in /usr/local/share/openscad/libraries (at least for Ubuntu) Then add it using:
use

Calling it:
roundCornersCube(x,y,z,r) Where:

  • x = Xdir width
  • y = Ydir width
  • z = Height of the cube
  • r = Rounding radious

    Example: roundCornerCube(10,10,2,1);
    *Some times it's needed to use F6 to see good results!

Preview of the code: http://codeviewer.org/view/code:1b36

All Apps

Upgrade this Thing with Thingiverse Apps


No results.

I updated this library to allow you to select the axis to round edges on.

Simply Use roundedRectX, roundedRectY, or roundedRectZ...

I also cleaned up the code considerably, and standardized the formatting. There may be mistakes, but I thought I would share.

// This module creates the shape that needs to be subtracted from a cube to make its corners rounded.

module createMeniscus(height, radius){

rrhide = 0.001;

//This shape is basicly the difference between a quarter of cylinder and a cube

difference(){

    translate([radius/2 + rrhide, radius/2 + rrhide]){

        cube([radius + rrhide, radius + rrhide, height + rrhide], center=true); 

    }

    cylinder(h = height, r = radius, $fn = 25, center=true);

}

}

// Now we just substract the shape we have created in the four corners

module roundedRect(xu, yu, zu, ru) {

rotation = 0;

difference(){

    cube([xu, yu, zu], center=true);

    translate([xu/2-ru, yu/2-ru]){

        rotate(0){  

            createMeniscus(zu, ru); 

        }

    }

    translate([-xu/2+ru, yu/2-ru]){

        rotate(90){

            createMeniscus(zu, ru);

        }

    }

    translate([-xu/2+ru, -yu/2+ru]){

        rotate(180){

            createMeniscus(zu, ru);

        }

    }

    translate([xu/2-ru, -yu/2+ru]){

        rotate(270){

            createMeniscus(zu, ru);

        }

    }

}

}

module roundedRectX(x, y, z, r){

rotate([90,0,90]){

    roundedRect(y, z, x, r);

}

}

module roundedRectY(x, y, z, r){

rotate([0,90,90]){

    roundedRect(z, x, y, r);

}

}

module roundedRectZ(x, y, z, r){

roundedRect(x, y, z, r);

}

I'd be nicer if you could just do cube([10,10,10], r=3) and stuff like in implicitCADhttp://www.implicitcad.org/). Maybe you can poke them into adding it?

I thought I'd leave this here for anyone to find. Its a quick rounded corner cube module that doesn't make the cube centred. I've only been doing openScad for a day so please point me in the right direction if this is stupid/has glaring mistakes.

module createSubtractor(h,radius) //Create the shape that needs to be substracted from a cube
difference(){ cube([radius+0.1,radius+0.1,h]); cylinder(h=h,r=radius+0.1,$fn = 25); } //+0.1 stops ghost edges

module rCube(x,y,z,r)//Create a cube and subtract the 4 corners
difference(){
cube([x,y,z]);
translate([x-r,y-r]) rotate(0) createSubtractor(z,r);
translate([r,y-r]) rotate(90) createSubtractor(z,r);
translate([r,r]) rotate(180) createSubtractor(z,r);
translate([x-r,r]) rotate(270) createSubtractor(z,r);
}

grrr... "The code snippet has expired".

In my openscad libraries directory there is boxes.scad, which includes roundedBox(size, radius, sidesonly). I'm pretty sure it's in the standard openscad distribution. It it different from what you are doing?

Emmm, you couldn't be more right!

It seems that I've rewritten one of the few standard functions in OpenScad. This is a newbie (what I am) error: not looking well if something was done previously!

And yes, the standard function is better: you can choose to round the object in 3D (the corners appear as spheres).

Now I have an exam, but once I'm back I'll edit the post (maybe rename it to "How to start writting your OpenScad library"?), and I'll make clear that there is a better function installed in the standard distribution.

Thanks for noticing me that there is a standard library! 8-)

Very cool! Thanks for sharing this.

Top