Search code examples
curveopenscad

How to a make a curved sheet (cube) in OpenSCAD?


How can I curve a sheet (cube)? I'd like to control the angle of the bend/curve.

curve

e.g.

cube([50,50,2]);


Solution

  • You can rotate_extrude() an rectangle with the parameter angle. This requires the openscad version 2016.xx or newer, see documentation. It is necessary to install a development snapshot, see download openscad

    $fn= 360;
    
    width = 10;   // width of rectangle
    height = 2;   // height of rectangle
    r = 50;       // radius of the curve
    a = 30;       // angle of the curve
    
    rotate_extrude(angle = a) translate([r, 0, 0]) square(size = [height, width], center = true);
    

    looks like this:

    enter image description here

    The curve is defined by radius and angle. I think it is more realistic, to use other dimensions like length or dh in this sketch

    enter image description here

    and calculate radius and angle

    $fn= 360;
    
    w = 10;       // width of rectangle
    h = 2;       // height of rectangle
    l = 25;      // length of chord of the curve
    dh = 2;           // delta height of the curve
    
    module curve(width, height, length, dh) {
        // calculate radius and angle
        r = ((length/2)*(length/2) - dh*dh)/(2*dh);
        a = asin((length/2)/r);
        rotate_extrude(angle = a) translate([r, 0, 0]) square(size = [height, width], center = true);
    }
    
    curve(w, h, l, dh);
    

    Edit 30.09.2019: considering comment of Cfreitas, additionally moved the resulting shape to origin, so dimensions can be seen on axes of coordinates

    $fn= 360;
    
    w = 10;       // width of rectangle
    h = 2;       // height of rectangle
    l = 30;      // length of chord of the curve
    dh = 4;           // delta height of the curve
    
    module curve(width, height, length, dh) {
        r = (pow(length/2, 2) + pow(dh, 2))/(2*dh);
        a = 2*asin((length/2)/r);
        translate([-(r -dh), 0, -width/2]) rotate([0, 0, -a/2])         rotate_extrude(angle = a) translate([r, 0, 0]) square(size = [height, width], center = true);
    }
    
    curve(w, h, l, dh);
    

    and the result:

    enter image description here

    Edit 19.09.2020: There was a typo in the last edit: In the first 'translate' the local 'width' should be used instead of 'w'. Corrected it in the code above.