You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenSCAD技术求助:如何实现圆柱上环绕中心孔的旋转排列?

OpenSCAD 圆柱错位旋转孔解决方案

问题分析

你的代码存在两个关键问题:

  • 用2D的circle()挖3D圆柱,只会在z=0平面生成一个薄片切口,无法贯穿整个圆柱。
  • 当前三组孔(hole1/hole2/hole3)共用同一个旋转角度,会在同一条径向线上对齐,无法实现错位旋转排列的效果。

修正后的代码

h=150;
r_cylinder=62.5;
r_hole1=2;
r_hole2=3;
r_hole3=4;
r_bighole=15;
distance=30;
n=24; 
$fn=120;
// 每组孔的旋转偏移角度,让三组孔错开排列
offset_angle = 360/(n*3);

difference()
{
  cylinder(h, r_cylinder, r_cylinder, center=true);
  // 中心大孔
  cylinder(h+1, r_bighole, r_bighole, center=true); 
  
  for(i=[1:n])
  {
    // 内层孔:基础角度
    translate([distance*cos(i*(360/n)), distance*sin(i*(360/n)), 0])
      cylinder(h+1, r_hole1, r_hole1, center=true);
    // 中层孔:基础角度+偏移量
    translate([(distance+10)*cos(i*(360/n) + offset_angle), (distance+10)*sin(i*(360/n) + offset_angle), 0]) 
      cylinder(h+1, r_hole2, r_hole2, center=true);
    // 外层孔:基础角度+2倍偏移量
    translate([(distance+20)*cos(i*(360/n) + offset_angle*2), (distance+20)*sin(i*(360/n) + offset_angle*2), 0]) 
      cylinder(h+1, r_hole3, r_hole3, center=true); 
  } 
}

关键修改点

  • 将circle(r_hole1)替换为cylinder(h+1, r_hole1, r_hole1, center=true),确保孔完全贯穿圆柱(h+1是为了避免因精度问题导致孔边缘残留)。
  • 新增offset_angle变量,计算每组孔的旋转偏移值(360/(n*3)表示把360度平均分成3*n份,每组孔占一份偏移),让三组孔在环形上错位分布。
  • 分别给hole2和hole3的角度加上offset_angle和offset_angle*2,实现三组孔的旋转错位排列。

调整建议

如果需要调整错位的间距,直接修改offset_angle的值即可:

  • 增大偏移值:三组孔的错开幅度更大
  • 减小偏移值:三组孔更接近对齐

内容的提问来源于stack exchange,提问作者misia91989

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 20:12:55