效果图: 
 
 把原作者使用全局变量的代码删掉了,全部改为了使用参数传递进模块里(以便在一个工程里创建多个不同的铰链)。- //code from Internet (learn.cadhub.xyz), modified by Tesla.Angela (www.m5home.com/bbs)
 
  
- $fn=100;
 
  
- module hingeBaseProfile
 
 - (
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         translate([pivotRadius,0,0])
 
 -         {
 
 -                 square([baseWidth,baseThickness]);
 
 -         }
 
 - }
 
  
- module plateHoles
 
 - (
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
 
 -                                                           (mountingHoleCount-1);
 
 -         for(i=[0:mountingHoleCount-1])
 
 -         {
 
 -                 translate([baseWidth/2+pivotRadius,
 
 -                                         -baseThickness,
 
 -                                         i*mountingHoleMoveIncrement+mountingHoleEdgeOffset])
 
 -                 {
 
 -                         rotate([-90,0,0])
 
 -                         {
 
 -                                 cylinder(r=mountingHoleRadius,h=baseThickness*4);
 
 -                         }
 
 -                 }
 
 -         }
 
 - }
 
  
- module hingeBodyHalf
 
 - (
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         hingeHalfExtrudeLength=hingeLength/2-clearance/2;
 
 -         difference()
 
 -         {
 
 -                 union()
 
 -                 {
 
 -                         linear_extrude(hingeHalfExtrudeLength)
 
 -                         {
 
 -                                 offset(1)offset(-2)offset(1)
 
 -                                 {
 
 -                                         translate([0,pivotRadius,0])
 
 -                                         {
 
 -                                                 circle(pivotRadius);
 
 -                                         }
 
 -                                         square([pivotRadius,pivotRadius]);
 
 -                                         hingeBaseProfile(baseWidth,hingeLength,baseThickness,
 
 -                                                                         pivotRadius,pinRadius,pinTaper,
 
 -                                                                         mountingHoleRadius,mountingHoleCount,
 
 -                                                                         mountingHoleEdgeOffset,clearance,
 
 -                                                                         tiny);
 
 -                                 }
 
 -                         }
 
 -                         linear_extrude(hingeLength)
 
 -                         {
 
 -                                 offset(1)offset(-1)hingeBaseProfile();
 
 -                         }
 
 -                 }
 
 -                 plateHoles(baseWidth,hingeLength,baseThickness,pivotRadius,
 
 -                                         pinRadius,pinTaper,mountingHoleRadius,
 
 -                                         mountingHoleCount,mountingHoleEdgeOffset,clearance,
 
 -                                         tiny);
 
 -         }
 
 - }
 
  
- module pin
 
 - (
 
 -         rotateY, 
 
 -         radiusOffset,
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         hingeHalfExtrudeLength=hingeLength/2-clearance/2;
 
 -         translate([0,pivotRadius,hingeHalfExtrudeLength+tiny])
 
 -         {
 
 -                 rotate([0,rotateY,0])
 
 -                 {
 
 -                         cylinder(h=hingeLength/2+clearance/2,
 
 -                                         r1=pinRadius+radiusOffset,
 
 -                                         r2=pinRadius+pinTaper+radiusOffset);
 
 -                 }
 
 -         }
 
 - }
 
  
- module hingeHalfFemale
 
 - (
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         difference()
 
 -         {
 
 -                 hingeBodyHalf(baseWidth,hingeLength,baseThickness,pivotRadius,
 
 -                                                 pinRadius,pinTaper,mountingHoleRadius,
 
 -                                                 mountingHoleCount,mountingHoleEdgeOffset,clearance,
 
 -                                                 tiny);
 
 -                 pin(180,clearance,baseWidth,hingeLength,baseThickness,pivotRadius,
 
 -                         pinRadius,pinTaper,mountingHoleRadius,mountingHoleCount,
 
 -                         mountingHoleEdgeOffset,clearance,tiny);
 
 -         }
 
 - }
 
  
- module hingeHalfMale
 
 - (
 
 -         baseWidth=20,
 
 -         hingeLength=28,
 
 -         baseThickness=3,
 
 -         pivotRadius=5,
 
 -         pinRadius=2,
 
 -         pinTaper=0.25,
 
 -         mountingHoleRadius=1.5,
 
 -         mountingHoleCount=3,
 
 -         mountingHoleEdgeOffset=4,
 
 -         clearance=0.3,
 
 -         tiny=0.005
 
 - )
 
 - {
 
 -         translate([0,0,hingeLength])
 
 -         {
 
 -                 rotate([0,180,0])
 
 -                 {
 
 -                         hingeBodyHalf(baseWidth,hingeLength,baseThickness,pivotRadius,
 
 -                                                         pinRadius,pinTaper,mountingHoleRadius,
 
 -                                                         mountingHoleCount,mountingHoleEdgeOffset,
 
 -                                                         clearance,tiny);
 
 -                         pin(0,0,baseWidth,hingeLength,baseThickness,pivotRadius,
 
 -                                 pinRadius,pinTaper,mountingHoleRadius,
 
 -                                 mountingHoleCount,mountingHoleEdgeOffset,
 
 -                                 clearance,tiny);
 
 -                 }
 
 -         }
 
 - }
 
  
- //test
 
 - translate([-30,0,0])
 
 - {
 
 -         rotate([90,180,0])
 
 -         {
 
 -                 hingeHalfFemale(10,20,3,5,2,0.25,1.5,2);
 
 -                 #hingeHalfMale(10,20,3,5,2,0.25,1.5,2);
 
 -         }
 
 - }
 
 - translate([30,0,0])
 
 - {
 
 -         rotate([90,180,0])
 
 -         {
 
 -                 hingeHalfFemale(20,40);
 
 -                 #hingeHalfMale(20,40);
 
 -         }
 
 - }
 
  复制代码 |