跳到内容

OpenSCAD 用户手册/过小的圆形物体

来自维基教科书,开放的世界中的开放书籍

使用 cylinder() 与 difference() 在对象中放置孔会导致孔过小。这是因为圆形路径是用内接于圆的多边形近似的。多边形的点在圆上,但它们之间的直线在圆内。这在http://hydraraptor.blogspot.com.au/2011/02/polyholes.html中详细讨论。

虽然标准的 cylinder() 和 circle() 生成内部(内接)多边形,但这里有一些模块可以生成外部(外接)和中间(1/2 路径之间)多边形。

圆柱体

[编辑 | 编辑源代码]
 module cylinder_outer(height,radius,fn){
   fudge = 1/cos(180/fn);
   cylinder(h=height,r=radius*fudge,$fn=fn);}
 module cylinder_mid(height,radius,fn){
   fudge = (1+1/cos(180/fn))/2;
   cylinder(h=height,r=radius*fudge,$fn=fn);}
Example of outer and mid cylinder
外部和中间圆柱体的示例
partial view
部分视图
 //example script to show differences
 cylinder_outer(5,100,6);
 %cylinder_mid(5.5,100,6);
 cylinder(6,r=100,$fn=6);        // standard
 #cylinder(5.75,r=100,$fn=60);   // reference
 //CSG tree for this example
 group() {
   group() {
     cylinder($fn = 6, $fa = 12, $fs = 2, h = 5, r1 = 115.47, r2 = 115.47, center = false);
   }
 % group() {
     cylinder($fn = 6, $fa = 12, $fs = 2, h = 5.5, r1 = 107.735, r2 = 107.735, center = false);
   }
   cylinder($fn = 6, $fa = 12, $fs = 2, h = 6, r1 = 100, r2 = 100, center = false);
 # cylinder($fn = 60, $fa = 12, $fs = 2, h = 5.75, r1 = 100, r2 = 100, center = false);
 }

对于顶部和底部半径不同的圆柱体

 module cone_outer(height,radius1,radius2,fn){
   fudge = 1/cos(180/fn);
   cylinder(h=height,r1=radius1*fudge,r2=radius2*fudge,$fn=fn);}
 module cone_mid(height,radius1,radius2,fn){
   fudge = (1+1/cos(180/fn))/2;
   cylinder(h=height,r1=radius1*fudge,r2=radius2*fudge,$fn=fn);}
 cone_outer(5 ,10 ,5 ,6);
 cone_mid(5 ,10 ,5 ,6);

最后不要忘记二维世界

   module circle_outer(radius,fn){
     fudge = 1/cos(180/fn);
     circle(r=radius*fudge,$fn=fn);}
   module circle_mid(radius,fn){
     fudge = (1+1/cos(180/fn))/2;
     circle(r=radius*fudge,$fn=fn);}
 circle_outer(20,6);
 circle_mid(20,6);
华夏公益教科书