Close



Results 1 to 5 of 5
  1. #1
    Technician DrUsual's Avatar
    Join Date
    Nov 2014
    Location
    Republic of Texas
    Posts
    69

    First OpenSCAD attempt - pressure fit box collar

    This is my first attempt at an OpenSCAD script for something functional; if anyone has suggestions for improvement they're happily accepted.

    Curious Aardvark sent a script about a month ago to solve a similar problem with a cylinder: make one half of a box fit snugly into the opposite half. The cylinder function is nice in that you can specify separate diameters for the top and bottom. With the cube function, though, the most straightforward method I came up with was to iterate through a loop and make a series of very thin boxes with an incremental change to the dimensions.

    This is just the half with the slope -- I'd generated the matching receptacle separately. The sides on that half don't slope.


    //Rectangular Pressure Sleeve by DrUsual
    mbd=50; //main box depth
    mbl=90; //main box length
    mbt=4; //main box wall thickness

    inh=5; //height of the insert overlap

    dd=.1; //difference in width and depth dimensions with each layer

    ist=2; //inside sleeve thickness
    isd=mbd - ist * 2 - dd; //inside sleeve starting depth
    isl=mbl - ist * 2 - dd; //inside sleeve starting length
    ish=1; //inside sleeve layer height

    union() {
    //Main box below the sleeve

    difference() {
    cube([mbd, mbl, 5], true);
    cube([mbd-mbt*2, mbl-mbt*2, 5], true);
    }

    //First layer of the sleeve
    translate([0, 0, 2.5])

    difference(){
    cube([isd, isl, ish], true);
    cube([isd-ist*2, isl-ist*2, ish], true);
    }

    //Additional sleeve layers

    for (x = [1 : 4] ) {
    translate([0, 0, 2.5 + x*ish])

    difference(){
    cube([isd - dd*x, isl - dd*x, ish], true);
    cube([isd-ist*2, isl-ist*2, ish], true);
    }
    }


    }

  2. #2
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    ah - it's actually just as easy to do it with a cube - but you use the hull command :-)

    hang on I'll knock one up... brb

    ps. I don't write tidy scripts, have yet to get to grips with modules and don't do any maths more complex than -,+,/ and *

  3. #3
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    right I'll do this without hull so you can see how it works.

    //pressure fit non cylindrical box




    //forming a cube that is narrower at the top than the bottom.
    cube([50,50,2]); //base plate


    translate([10,10,20]) cube([30,30,1]); //add shape

    That produces:


    Usually I make the lines or shapes all a least 0.1mm in thickness as - but gave these a bit of height so you can see them :-)
    However that produces a 1 mm ledge. For a sharp edge just use a really small height. For some model railway wheels I think I used 0.001 thickness.
    So we start with a base cube and create another one centred and above.

    We then hull them:
    //pressure fit non cylindrical box



    //forming a cube that is narrower at the top than the bottom.


    hull() {
    cube([50,50,2]); //base plate


    translate([10,10,20]) cube([30,30,1]); //add shape
    } //end of hull
    And get this:



    Once you've got the shape you can resize and difference or just make a smaller version and difference.
    Basically once you've got the hang of of hull you can make pretty much irregular shape you like :-)

    I've used quite big differences to easily illustrate the function. But obviously you can make the slope as large or small as you like.
    And use as many or as few shapes as you like to create the hull.

    Want to make a wedge ?
    Just hull a tall thin block and a long short block:
    hull() { cube([0.1,20,30]);
    cube([100,20,0.1]);
    }
    without hull:


    With hull:


    So making push fit 'square' boxes is just as easy as cylindrical boxes just use a hulled shape :-)
    Attached Images Attached Images

  4. #4
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    I did try and tidy the above post up - but kept getting the bloody stupid: 'please add 10 more characters' bug and gave up :-)

    So essentially you can make a slope sided box in about 6 lines and a difference command: 3 for the box and 3 for the smaller differenced one.
    Throw in some variables and you can easily make it parametric.

    If that's still not clear - let me know.

    I was really struggling with irregular shapes before I started using hull.
    No problems with any shape since. :-)

  5. #5
    Super Moderator curious aardvark's Avatar
    Join Date
    Jul 2014
    Posts
    8,818
    You don't have to stick to cubes with cubes either. Want something with a square base and a round top. Just hull a cube and a cylinder:
    $fn=100;

    hull() {
    cube([10,20,0.1],center=true);
    translate([0,0,10]) cylinder(d=10,h=0.1);
    }


    Try a few things. To make a rectangular bottle with a round top try this:

    $fn=100;

    hull() {
    cube([10,20,20],center=true);
    translate([0,0,10]) cylinder(d=10,h=10);
    }
    basically the hull starts at the top of the objects. So even though I made the cylinder longer, hull ignores everythig but the top.
    you'd just need to add a second cylinder (outside the hull command) on top of the first to get a completely round top.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •