找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 719|回复: 0

[代码建模] OpenSCAD基本组件:铰链

[复制链接]

857

主题

2632

回帖

2

精华

管理员

此生无悔入华夏,  长居日耳曼尼亚。  

积分
36130
发表于 2024-1-16 05:59:26 | 显示全部楼层 |阅读模式
效果图:
demo.png
把原作者使用全局变量的代码删掉了,全部改为了使用参数传递进模块里(以便在一个工程里创建多个不同的铰链)。
  1. //code from Internet (learn.cadhub.xyz), modified by Tesla.Angela (www.m5home.com/bbs)

  2. $fn=100;

  3. module hingeBaseProfile
  4. (
  5.         baseWidth=20,
  6.         hingeLength=28,
  7.         baseThickness=3,
  8.         pivotRadius=5,
  9.         pinRadius=2,
  10.         pinTaper=0.25,
  11.         mountingHoleRadius=1.5,
  12.         mountingHoleCount=3,
  13.         mountingHoleEdgeOffset=4,
  14.         clearance=0.3,
  15.         tiny=0.005
  16. )
  17. {
  18.         translate([pivotRadius,0,0])
  19.         {
  20.                 square([baseWidth,baseThickness]);
  21.         }
  22. }

  23. module plateHoles
  24. (
  25.         baseWidth=20,
  26.         hingeLength=28,
  27.         baseThickness=3,
  28.         pivotRadius=5,
  29.         pinRadius=2,
  30.         pinTaper=0.25,
  31.         mountingHoleRadius=1.5,
  32.         mountingHoleCount=3,
  33.         mountingHoleEdgeOffset=4,
  34.         clearance=0.3,
  35.         tiny=0.005
  36. )
  37. {
  38.         mountingHoleMoveIncrement=(hingeLength-2*mountingHoleEdgeOffset)/
  39.                                                           (mountingHoleCount-1);
  40.         for(i=[0:mountingHoleCount-1])
  41.         {
  42.                 translate([baseWidth/2+pivotRadius,
  43.                                         -baseThickness,
  44.                                         i*mountingHoleMoveIncrement+mountingHoleEdgeOffset])
  45.                 {
  46.                         rotate([-90,0,0])
  47.                         {
  48.                                 cylinder(r=mountingHoleRadius,h=baseThickness*4);
  49.                         }
  50.                 }
  51.         }
  52. }

  53. module hingeBodyHalf
  54. (
  55.         baseWidth=20,
  56.         hingeLength=28,
  57.         baseThickness=3,
  58.         pivotRadius=5,
  59.         pinRadius=2,
  60.         pinTaper=0.25,
  61.         mountingHoleRadius=1.5,
  62.         mountingHoleCount=3,
  63.         mountingHoleEdgeOffset=4,
  64.         clearance=0.3,
  65.         tiny=0.005
  66. )
  67. {
  68.         hingeHalfExtrudeLength=hingeLength/2-clearance/2;
  69.         difference()
  70.         {
  71.                 union()
  72.                 {
  73.                         linear_extrude(hingeHalfExtrudeLength)
  74.                         {
  75.                                 offset(1)offset(-2)offset(1)
  76.                                 {
  77.                                         translate([0,pivotRadius,0])
  78.                                         {
  79.                                                 circle(pivotRadius);
  80.                                         }
  81.                                         square([pivotRadius,pivotRadius]);
  82.                                         hingeBaseProfile(baseWidth,hingeLength,baseThickness,
  83.                                                                         pivotRadius,pinRadius,pinTaper,
  84.                                                                         mountingHoleRadius,mountingHoleCount,
  85.                                                                         mountingHoleEdgeOffset,clearance,
  86.                                                                         tiny);
  87.                                 }
  88.                         }
  89.                         linear_extrude(hingeLength)
  90.                         {
  91.                                 offset(1)offset(-1)hingeBaseProfile();
  92.                         }
  93.                 }
  94.                 plateHoles(baseWidth,hingeLength,baseThickness,pivotRadius,
  95.                                         pinRadius,pinTaper,mountingHoleRadius,
  96.                                         mountingHoleCount,mountingHoleEdgeOffset,clearance,
  97.                                         tiny);
  98.         }
  99. }

  100. module pin
  101. (
  102.         rotateY,
  103.         radiusOffset,
  104.         baseWidth=20,
  105.         hingeLength=28,
  106.         baseThickness=3,
  107.         pivotRadius=5,
  108.         pinRadius=2,
  109.         pinTaper=0.25,
  110.         mountingHoleRadius=1.5,
  111.         mountingHoleCount=3,
  112.         mountingHoleEdgeOffset=4,
  113.         clearance=0.3,
  114.         tiny=0.005
  115. )
  116. {
  117.         hingeHalfExtrudeLength=hingeLength/2-clearance/2;
  118.         translate([0,pivotRadius,hingeHalfExtrudeLength+tiny])
  119.         {
  120.                 rotate([0,rotateY,0])
  121.                 {
  122.                         cylinder(h=hingeLength/2+clearance/2,
  123.                                         r1=pinRadius+radiusOffset,
  124.                                         r2=pinRadius+pinTaper+radiusOffset);
  125.                 }
  126.         }
  127. }

  128. module hingeHalfFemale
  129. (
  130.         baseWidth=20,
  131.         hingeLength=28,
  132.         baseThickness=3,
  133.         pivotRadius=5,
  134.         pinRadius=2,
  135.         pinTaper=0.25,
  136.         mountingHoleRadius=1.5,
  137.         mountingHoleCount=3,
  138.         mountingHoleEdgeOffset=4,
  139.         clearance=0.3,
  140.         tiny=0.005
  141. )
  142. {
  143.         difference()
  144.         {
  145.                 hingeBodyHalf(baseWidth,hingeLength,baseThickness,pivotRadius,
  146.                                                 pinRadius,pinTaper,mountingHoleRadius,
  147.                                                 mountingHoleCount,mountingHoleEdgeOffset,clearance,
  148.                                                 tiny);
  149.                 pin(180,clearance,baseWidth,hingeLength,baseThickness,pivotRadius,
  150.                         pinRadius,pinTaper,mountingHoleRadius,mountingHoleCount,
  151.                         mountingHoleEdgeOffset,clearance,tiny);
  152.         }
  153. }

  154. module hingeHalfMale
  155. (
  156.         baseWidth=20,
  157.         hingeLength=28,
  158.         baseThickness=3,
  159.         pivotRadius=5,
  160.         pinRadius=2,
  161.         pinTaper=0.25,
  162.         mountingHoleRadius=1.5,
  163.         mountingHoleCount=3,
  164.         mountingHoleEdgeOffset=4,
  165.         clearance=0.3,
  166.         tiny=0.005
  167. )
  168. {
  169.         translate([0,0,hingeLength])
  170.         {
  171.                 rotate([0,180,0])
  172.                 {
  173.                         hingeBodyHalf(baseWidth,hingeLength,baseThickness,pivotRadius,
  174.                                                         pinRadius,pinTaper,mountingHoleRadius,
  175.                                                         mountingHoleCount,mountingHoleEdgeOffset,
  176.                                                         clearance,tiny);
  177.                         pin(0,0,baseWidth,hingeLength,baseThickness,pivotRadius,
  178.                                 pinRadius,pinTaper,mountingHoleRadius,
  179.                                 mountingHoleCount,mountingHoleEdgeOffset,
  180.                                 clearance,tiny);
  181.                 }
  182.         }
  183. }

  184. //test
  185. translate([-30,0,0])
  186. {
  187.         rotate([90,180,0])
  188.         {
  189.                 hingeHalfFemale(10,20,3,5,2,0.25,1.5,2);
  190.                 #hingeHalfMale(10,20,3,5,2,0.25,1.5,2);
  191.         }
  192. }
  193. translate([30,0,0])
  194. {
  195.         rotate([90,180,0])
  196.         {
  197.                 hingeHalfFemale(20,40);
  198.                 #hingeHalfMale(20,40);
  199.         }
  200. }
复制代码
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表