Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <craft>
- <info>
- <title>Hinge</title>
- </info>
- <parameter name="width" type="int" default="10"/>
- <script type="text/openjscad">
- function main(params) {
- var width = params.width;
- var hinge = mathhinge(width*2, width/2)
- .scale([0.5,0.5,0.5]);
- var slot = slotgenerator(width)
- .translate([0,5,0])
- //return hinge;
- return union(
- hinge,
- slot
- )
- } // end of main
- function slotgenerator(w, h){
- var box = cube([w, 3, 3-1]) //y must be parameter but it exceed call stack
- return difference(
- box
- .scale([1.1,1.3,1.1]),
- box
- .translate([0.5,0.5,0.5])
- )
- }
- function mathhinge(w, h){
- var length = w; // Length of the complete hinge
- var height = h; // Height (diameter) of the hinge
- var clearance = 0.4; // Clearance between cones and holes
- var gap = 0.5; // Clearance between hinge and sides
- // Parameters that the user does not get to specify
- var fn=24*1;
- var border = 2*1;
- var fudge = .01*1; // to preserve mesh integrity
- var corner = 1*1; // space between hinge and corner
- var hinge_radius = height/2;
- var cone_height = 1.7*hinge_radius; //how to reflect that the cone height needs to be shorter than width?
- var hinge_module = hinge(hinge_radius, clearance, length, corner, cone_height, gap, fudge)
- .translate([-hinge_radius,0,0])
- .rotateY(90);
- var bar1 = bar(length, border, height)
- .translate([0, hinge_radius+gap, 0]);
- var bar2 = bar(length, border, height)
- .translate([0, -2*border-hinge_radius-gap, 0]);
- return union(hinge_module, bar1, bar2);
- }
- function hinge(hinge_radius, clearance,
- length, corner, cone_height, gap, fudge){
- var rad = hinge_radius;
- var clr = clearance;
- var len = (length-2*corner)/3;
- var con = cone_height;
- // left outside hinge = (cylinder+box)-cone
- var outside = difference(
- union(
- cylinder({h:len-clr,r:rad})
- .translate([0,0,corner]),
- cube([2*rad,rad+gap,len-clr])
- .translate([-rad,0,corner])
- ),
- cylinder({h:con,r1:0,r2:rad})
- .translate([0,0,corner+len-con-clr+fudge])
- )
- // inside hinge = cylinder+box+cone+cone
- var inside = union(
- cylinder({h:len,r:rad})
- .translate([0,0,corner+len]),
- cube([2*rad,rad+gap,len])
- .translate([-rad,-rad-gap,corner+len]),
- cylinder({h:con,r1:0,r2:rad})
- .translate([0,0,corner+len-con]),
- cylinder({h:con,r1:rad,r2:0})
- .translate([0,0,corner+2*len])
- );
- // right outside hinge = (cylinder+box)-cone
- var right = union(
- cylinder({h:len-clr,r:rad})
- .translate([0,0,corner+2*len+clr]),
- cube([2*rad,rad+gap,len-clr])
- .translate([-rad,0,corner+2*len+clr])
- );
- right = difference(
- right,
- cylinder({h:con,r1:rad,r2:0})
- .translate([0,0,corner+2*len+clr-fudge])
- );
- return union(outside, inside, right);
- }
- function bar(length, border, height){
- return cube([length,2*border,height]);
- }
- </script>
- </craft>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement