OpenSCAD 3D Printed Spring

OpenSCAD spring design by @rasterweb

“I’m trying to come up with a good way of creating this in OpenSCAD… I have something using a bunch of hull’d cylinders but I’m wondering if there is a better/easier way to do it.” @rasterweb

A friend posted a design pondering whether there was a better way to design an object in OpenSCAD.  As so often happens when I approach a 3D design, one solution pops up in my head… and is immediately discarded as garbage.  That first thought was to create a negative of the interior of the spring, then iterate along the length of a stretched cube.

In the end, I opted for1 creating a flat version of a single “loop”, made from differenced hulled circles, repeated over the number of desired loops, then trimming alternating ends (so it wouldn’t look like a chain).

OpenSCAD spring by MakerBlock

OpenSCAD spring by MakerBlock

Here’s the OpenSCAD code to produce this spring:2

//  Settings
    $fn = pow(2,6);
//  Spring Dimensions
    springH     = 5;
    springOD    = 10;
    springW     = springOD*2;
    springOR    = springOD/2;
    springTh    = 2;
    springIR    = springOR-springTh;
    loops       = 8;

    spring();

module spring()
    {
    linear_extrude(height=springH, center=false)
    for (i=[0:loops])
        {
        translate([0,(springOD-springTh)*i,0])
            difference()
                {
                spring_loop();
                translate([-springOR+(springW+springOD)*(i%2),0,0]) 
                    square(springOD, center=true);
                }
        }
    }
    
module spring_loop()
    {
    difference()
        {
        hull()
            {
            circle(r=springOR);
            translate([springW,0,0])
                circle(r=springOR);
            }
        hull()
            {
            circle(r=springIR);
            translate([springW,0,0])
                circle(r=springIR);
            }
        }
    }

Some notes about my OpenSCAD style:

  • I like to use OD/ID/OR/IR to mean outer diameter, inner diameter, outer radius, inner radius.
  • I think the “spring_loop” module could be simplified slightly by calling another module which creates each hulled circle, but weighing the additional module code against just retyping a little code I opted for what got it done faster.
  • I like to specify the facets on circular objects right at the top of the file. This way, I can adjust the smoothness of the object by just changing just the exponent part of the $fn system variable.
  • Reasonably parametric. There’s some additional further optimization that could be done in the spring alternate end clipping.

Can’t wait to see what @rasterweb makes with a 3D printed spring!

  1. And, please forgive the inside-baseball / OpenSCAD-speak []
  2. To display the code above I had to use the WordPress block editor. 🤮 []

Leave a Reply

Your email address will not be published. Required fields are marked *