openscad3d-printing

OpenSCAD Hourglass Beam


I'm trying to make a rounded beam in OpenSCAD, I made it rounded by joining two circles and a cube.

Here is the current OpenSCAD script and output:

    // Parameters for the plate and holes
nx_beam_length = 58.4; // Length of the plate
ny_beam_width = 8.0; // Width of the plate
nz_beam_thickness = 2.0; // Thickness of the plate
nx_hole_interaxis = 50.0; // Distance between the centers of the holes
nd_hole = 2.2; // Diameter of the holes

// Translate the entire structure up by half the thickness of the plate
// This is done so that the plate is centered at the origin along the z-axis
translate([0,0,nz_beam_thickness/2])
difference() // Subtracts the second shape (the holes) from the first shape (the plate)
{
    union() // Combines multiple shapes into one
    {
        // The main part of the plate, a cube with the specified length, width, and thickness
        // The length is reduced by the width of the plate to make room for the cylinders at the ends
        cube([nx_beam_length - ny_beam_width, ny_beam_width, nz_beam_thickness], center=true);
        
        // A cylinder at one end of the plate to create a rounded corner
        // The cylinder is translated to the end of the cube
        // The diameter of the cylinder is equal to the width of the plate
        translate([-(nx_beam_length - ny_beam_width)/2, 0, 0]) cylinder(h=nz_beam_thickness, d=ny_beam_width, center=true, $fn=50);
        
        // A cylinder at the other end of the plate to create a rounded corner
        // The cylinder is translated to the end of the cube
        // The diameter of the cylinder is equal to the width of the plate
        translate([(nx_beam_length - ny_beam_width)/2, 0, 0]) cylinder(h=nz_beam_thickness, d=ny_beam_width, center=true, $fn=50);
    }
    
    // A hole at one side of the plate
    // The hole is a cylinder with the specified diameter and a height slightly larger than the thickness of the plate
    // The hole is translated to the correct location on the plate
    translate([nx_hole_interaxis/2, 0, 0]) cylinder(h=nz_beam_thickness+1, r=nd_hole/2, center=true, $fn=50);
    
    // A hole at the other side of the plate
    // The hole is a cylinder with the specified diameter and a height slightly larger than the thickness of the plate
    // The hole is translated to the correct location on the plate
    translate([-nx_hole_interaxis/2, 0, 0]) cylinder(h=nz_beam_thickness+1, r=nd_hole/2, center=true, $fn=50);
}

enter image description here

Now I want to make the center thinner in a hourglass like shape like this sketch, with a parametric center width (starting from 6.0mm) enter image description here

How can I do it?


Solution

  • SOLUTION

    The rounded poly library does exactly what I need it to do and it works well.

    I added two features to the final beam:

    enter image description here

    Below, the code to generate the beam, it depends on the rounded poly library, and my suspended_hole library

    //! @author Orso Eric https://github.com/OrsoEric
    
    include <polyround.scad>
    include <suspended_hole.scad>
    
    // Parameters for the plate and holes
    nx_beam_length = 58.4; // Length of the plate
    ny_beam_width = 8.0; // Width of the plate
    gny_beam_width_narrow = 4.0; //The beam narrows in the center
    nz_beam_thickness = 2.5; // Thickness of the plate
    nx_hole_interaxis = 50.0; // Distance between the centers of the holes
    
    //Nut seat
    nd_nut_diameter = 5.0;
    nz_nut_thickness = 1.0;
    //rod
    nd_rod = 2.3;
    
    //Vertical fin to strengthen the beam
    flag_enable_fin = true;
    gnx_fin_length = 40;
    gny_fin_thickness = 1.5;
    gnz_fin_height = 3.0; // Height of the fin
    
    module rounded_fin( inx_length, iny_thickness, inz_height, inr_round_factor = 2)
    {
        aan_points =
        ([
            [-inx_length/2, 0, 0],
            [+inx_length/2, 0, 0],
            [+inx_length/2, inz_height, inr_round_factor *iny_thickness],
            [-inx_length/2, inz_height, inr_round_factor *iny_thickness],
        ]);
        translate([0,iny_thickness/2,0])
        rotate([90,0,0])
        linear_extrude(iny_thickness)
        polygon(polyRound(aan_points,100));
    }
    
    module rounded_hourglass(inx_length, iny_width_wide, iny_width_narrow, inz_height, inr_round_factor_corner = 0.3, inr_round_factor_neck = 2 )
    {
        aan_points =
        ([
            [0, iny_width_narrow/2,inr_round_factor_neck *inx_length],
            [inx_length/2, iny_width_wide/2,inr_round_factor_corner *iny_width_wide],
            [inx_length/2, -iny_width_wide/2,inr_round_factor_corner *iny_width_wide],
            [0, -iny_width_narrow/2,inr_round_factor_neck *inx_length],
            [-inx_length/2, -iny_width_wide/2,inr_round_factor_corner *iny_width_wide],
            [-inx_length/2,  iny_width_wide/2, inr_round_factor_corner *iny_width_wide]
        ]);
    
        linear_extrude(inz_height)
        polygon(polyRound(aan_points,100));
    }
    
    module mini_pupper_bone_v2()
    {
        difference() 
        {
            union()
            {
                translate([0,0,0])
                rounded_hourglass(nx_beam_length, ny_beam_width, gny_beam_width_narrow, nz_beam_thickness );
    
                translate([0,0,nz_beam_thickness])
                rounded_fin( gnx_fin_length, gny_fin_thickness, gnz_fin_height );
            };
            union()
            {
                translate([-nx_hole_interaxis/2,0,0])
                suspended_hole
                (
                    nd_nut_diameter,
                    nz_nut_thickness,
                    nd_rod,
                    nz_beam_thickness -nz_nut_thickness,
                    0.5
                );
                translate([+nx_hole_interaxis/2,0,0])
                suspended_hole
                (
                    nd_nut_diameter,
                    nz_nut_thickness,
                    nd_rod,
                    nz_beam_thickness -nz_nut_thickness,
                    0.5
                );
            };
        }
    }
    
    mini_pupper_bone_v2();
    

    Below the result of test block with the two features enabled and disabled. With both enabled, I can 3D print a small hole stacked on top of a larger hole without it collapsing.

    enter image description here

    Below the content of "suspended_hole.scad", it solves the issue that I had of the shaft hole collapsing inside the nut hole when 3D printing.

    //! @author Orso Eric https://github.com/OrsoEric
    
    //Layer height of the 3D printer
    gn_layer_height = 0.2;
    
    module base_cylinder(in_diameter, in_height, in_precision = 5)
    {
        linear_extrude(in_height)
        circle(d = in_diameter, $fs = 0.1+in_precision, $fa = 0.1+in_precision*3/5);
    }
    
    module rounded_rectangle( inx_length, iny_length, inz_height, ind_rounding, in_precision = 0.5 )
    {
        linear_extrude( inz_height )
        union()
        {
            square([inx_length-ind_rounding,iny_length], center=true);
            
            square([inx_length,iny_length-ind_rounding], center=true);
            
            translate([-(inx_length/2-ind_rounding/2), -(iny_length/2-ind_rounding/2), 0])
            circle(d=ind_rounding, $fs = 0.1+in_precision, $fa = 0.1+in_precision*3/5);
            
            translate([-(inx_length/2-ind_rounding/2), +(iny_length/2-ind_rounding/2), 0])
            circle(d=ind_rounding, $fs = 0.1+in_precision, $fa = 0.1+in_precision*3/5);
            
            translate([+(inx_length/2-ind_rounding/2), -(iny_length/2-ind_rounding/2), 0])
            circle(d=ind_rounding, $fs = 0.1+in_precision, $fa = 0.1+in_precision*3/5);
            
            translate([+(inx_length/2-ind_rounding/2), +(iny_length/2-ind_rounding/2), 0])
            circle(d=ind_rounding, $fs = 0.1+in_precision, $fa = 0.1+in_precision*3/5);
            
        }
        
    }
    
    module suspended_hole( in_big_diameter, in_big_height, in_small_diameter, in_small_height, in_precision = 5, in_wide_feature = gn_layer_height, in_narrow_feature = gn_layer_height )
    {
        
        base_cylinder( in_big_diameter, in_big_height-in_wide_feature, in_precision );
        
        if (in_wide_feature > 0)
        translate([0,0,in_big_height-gn_layer_height])
        rounded_rectangle( in_big_diameter, in_small_diameter, in_wide_feature, in_big_diameter/3, in_precision/2);
        
        if (in_narrow_feature > 0)
        translate([0,0,in_big_height])
        rounded_rectangle( in_small_diameter, in_small_diameter, in_narrow_feature, in_small_diameter/3, in_precision/2);
        
        translate([0,0,in_big_height+in_narrow_feature])
        base_cylinder( in_small_diameter, in_small_height - in_narrow_feature, in_precision );
    }
    
    //Block with four styles of suspended holes with different combination of wide and narrow features
    module test_bench()
    {
        nd_hole_big = 8;
        nh_hole_big = 2;
        nd_hole_small = 3.2;
        nh_hole_small = 12;
    
        n_block_size = nd_hole_big *3;
        n_block_height = nh_hole_big +nh_hole_small;
    
        n_hole_pitch = nd_hole_big *0.75;
    
        difference()
        {
            union()
            {
                rounded_rectangle( n_block_size, n_block_size, n_block_height, 10);
            };
    
            translate([-n_hole_pitch, -n_hole_pitch, 0 ])
            suspended_hole(nd_hole_big, nh_hole_big, nd_hole_small, nh_hole_small, 0.5, 0, 0);
    
            translate([-n_hole_pitch, +n_hole_pitch, 0 ])
            suspended_hole(nd_hole_big, nh_hole_big, nd_hole_small, nh_hole_small, 0.5, gn_layer_height, 0);
    
            translate([+n_hole_pitch, -n_hole_pitch, 0 ])
            suspended_hole(nd_hole_big, nh_hole_big, nd_hole_small, nh_hole_small, 0.5, 0, gn_layer_height);
    
            translate([+n_hole_pitch, +n_hole_pitch, 0 ])
            suspended_hole(nd_hole_big, nh_hole_big, nd_hole_small, nh_hole_small, 0.5, gn_layer_height, gn_layer_height);
    
        }
    }
    
    
    //suspended_hole( 30, 5, 10, 20, 1, 0, 0 ); 
    //test_bench();