找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 694|回复: 0

[代码建模] OpenSCAD基本组件:空心圆柱、空心圆锥、空心半球、空心金字塔

[复制链接]

857

主题

2632

回帖

2

精华

管理员

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

积分
36130
发表于 2024-1-16 05:43:15 | 显示全部楼层 |阅读模式
效果图:
demo.png
这个代码风格照搬了我写WINDOWS驱动代码时的风格。
  1. //code by Tesla.Angela (www.m5home.com/bbs)

  2. $fn=100;

  3. module ObCreateHollowCylinder(radius,height,thickness,IsCone)
  4. {
  5.         difference()
  6.         {
  7.                 cylinder(height,radius,IsCone?0:radius);
  8.                 cylinder(height-thickness,radius-thickness,IsCone?0:radius-thickness);
  9.         }       
  10. }
  11. //demo
  12. translate([80,0,100])
  13. {
  14.         rotate([0,180,0])
  15.         {
  16.                 ObCreateHollowCylinder(50,100,2,0);
  17.         }
  18. }
  19. translate([-30,0,0])
  20. {
  21.         ObCreateHollowCylinder(50,100,2,1);
  22. }

  23. module ObCreateHollowHalfBall(radius,thickness)
  24. {
  25.         difference()
  26.         {
  27.                 sphere(radius);
  28.                 sphere(radius-thickness);
  29.                 translate([0,-radius,-radius])
  30.                 {
  31.                         cube([radius*2,radius*2,radius*2]);
  32.                 }
  33.         }
  34. }
  35. //demo
  36. translate([-30,110,50])
  37. {
  38.         rotate([0,270,0])
  39.         {
  40.                 ObCreateHollowHalfBall(50,2);
  41.         }
  42. }

  43. module ObpCreatePyramid(length, height)
  44. {
  45.         polyhedron
  46.         (
  47.                 points=[[0,length,0],[length,length,0],[length,0,0],[0,0,0],[length/2,length/2,height]],
  48.                 faces=[[0,1,4],[1,2,4],[2,3,4],[3,0,4],[3,2,1,0]]
  49.         );
  50. }
  51. module ObCreateHollowPyramid(length, height,thickness)
  52. {
  53.         difference()
  54.         {
  55.                 ObpCreatePyramid(length, height);
  56.                 translate([thickness/2,thickness/2,0])
  57.                 {
  58.                         ObpCreatePyramid(length-thickness, height-thickness);
  59.                 }
  60.         }
  61. }
  62. //demo
  63. translate([30,60,0])
  64. {
  65.         ObCreateHollowPyramid(100,100,10);
  66. }
复制代码
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

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