Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. <craft>
  2. <info>
  3. <title>Hinge</title>
  4. </info>
  5. <parameter name="width" type="int" default="10"/>
  6.  
  7. <script type="text/openjscad">
  8. function main(params) {
  9.  
  10. var width = params.width;
  11.  
  12. var hinge = mathhinge(width*2, width/2)
  13. .scale([0.5,0.5,0.5]);
  14. var slot = slotgenerator(width)
  15. .translate([0,5,0])
  16. //return hinge;
  17.  
  18. return union(
  19. hinge,
  20. slot
  21. )
  22.  
  23. } // end of main
  24.  
  25. function slotgenerator(w, h){
  26. var box = cube([w, 3, 3-1]) //y must be parameter but it exceed call stack
  27. return difference(
  28. box
  29. .scale([1.1,1.3,1.1]),
  30. box
  31. .translate([0.5,0.5,0.5])
  32. )
  33. }
  34.  
  35. function mathhinge(w, h){
  36.  
  37. var length = w; // Length of the complete hinge
  38. var height = h; // Height (diameter) of the hinge
  39. var clearance = 0.4; // Clearance between cones and holes
  40. var gap = 0.5; // Clearance between hinge and sides
  41.  
  42. // Parameters that the user does not get to specify
  43. var fn=24*1;
  44. var border = 2*1;
  45. var fudge = .01*1; // to preserve mesh integrity
  46. var corner = 1*1; // space between hinge and corner
  47. var hinge_radius = height/2;
  48. var cone_height = 1.7*hinge_radius; //how to reflect that the cone height needs to be shorter than width?
  49.  
  50.  
  51. var hinge_module = hinge(hinge_radius, clearance, length, corner, cone_height, gap, fudge)
  52. .translate([-hinge_radius,0,0])
  53. .rotateY(90);
  54.  
  55. var bar1 = bar(length, border, height)
  56. .translate([0, hinge_radius+gap, 0]);
  57. var bar2 = bar(length, border, height)
  58. .translate([0, -2*border-hinge_radius-gap, 0]);
  59.  
  60. return union(hinge_module, bar1, bar2);
  61.  
  62. }
  63.  
  64. function hinge(hinge_radius, clearance,
  65. length, corner, cone_height, gap, fudge){
  66. var rad = hinge_radius;
  67. var clr = clearance;
  68. var len = (length-2*corner)/3;
  69. var con = cone_height;
  70.  
  71. // left outside hinge = (cylinder+box)-cone
  72. var outside = difference(
  73. union(
  74. cylinder({h:len-clr,r:rad})
  75. .translate([0,0,corner]),
  76. cube([2*rad,rad+gap,len-clr])
  77. .translate([-rad,0,corner])
  78. ),
  79. cylinder({h:con,r1:0,r2:rad})
  80. .translate([0,0,corner+len-con-clr+fudge])
  81. )
  82. // inside hinge = cylinder+box+cone+cone
  83. var inside = union(
  84. cylinder({h:len,r:rad})
  85. .translate([0,0,corner+len]),
  86. cube([2*rad,rad+gap,len])
  87. .translate([-rad,-rad-gap,corner+len]),
  88. cylinder({h:con,r1:0,r2:rad})
  89. .translate([0,0,corner+len-con]),
  90. cylinder({h:con,r1:rad,r2:0})
  91. .translate([0,0,corner+2*len])
  92. );
  93.  
  94. // right outside hinge = (cylinder+box)-cone
  95. var right = union(
  96. cylinder({h:len-clr,r:rad})
  97. .translate([0,0,corner+2*len+clr]),
  98. cube([2*rad,rad+gap,len-clr])
  99. .translate([-rad,0,corner+2*len+clr])
  100. );
  101. right = difference(
  102. right,
  103. cylinder({h:con,r1:rad,r2:0})
  104. .translate([0,0,corner+2*len+clr-fudge])
  105. );
  106.  
  107. return union(outside, inside, right);
  108. }
  109.  
  110. function bar(length, border, height){
  111. return cube([length,2*border,height]);
  112. }
  113. </script>
  114. </craft>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement