OpenSCAD支持变量和循环,从而可以快速复制出大量的几何对象并且按照递归的方式进行布局。
循环的变量可以是枚举、区间和矢量对象,循环体支持几何对象构建、坐标平移与旋转、交并差等操作。
循环的递归变量类型
Vector(矢量):
for (variable=<vector>) {
<do_something> - <variable> is assigned to each successive value in the vector
}
Range(区间、范围):
for (variable=<range>) {
<do_something>
}
Nested(嵌套) :
for ( variable1 = <range or vector>, variable2 = <range or vector> ) {
<do something, using both variables>
}
for 循环可以进行嵌套,就像普通程序一样。
使用枚举型矢量的循环
Usage example 1 - 通过vector的循环调用 | |
| ![]() |
使用范围型变量的循环 |
Usage example 2a - 通过范围实现循环 | |
| |
使用范围型给定步长的循环 |
Usage example 2b -指定步长和范围的循环 |
|
Usage example 3 - 通过矢量的循环 (旋转) | |
| |
通过矢量数组的枚举型循环 |
Usage example 4 -矢量数组的循环(位移): | |
| |
循环的嵌套和多变量 |
嵌套循环的例程
for (xpos=[0:3], ypos = [2,4,6]) // do twelve iterations, using each xpos with each ypos
translate([xpos*ypos, ypos, 0])
cube([0.5, 0.5, 0.5]);
循环的切割
所有的循环(包括枚举值、范围、矢量、矢量数组)都支持几何实体的 intersection 操作。
注意:
intersection_for()
is a work around because of an issue that you cannot get the expected results using a combination of the standard
for()
and
intersection()
statements. The reason is that
for()
do a implicit
union()
of the contents.
参数
- <loop variable name>
- Name of the variable to use within the for loop.
Usage example 1 - 范围循环: | |
| |
Intersection for使用示例: |
Usage example 2 - rotation : | |
| |
版权声明:本文为CSDN博主「weixin_34001430」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_34001430/article/details/92207349