2

我不小心遗漏了翻译向量中的方括号。OpenSCAD 没有引起错误,而是默默地忽略了该错误。

带有多个参数的 translate() 有什么特殊含义吗?第二行应该怎么做?我附上了一张图片,显示了我得到的结果。

translate([5,5,-25]) color("red") cube([10,10,50]);
translate(5,5,-25) color("blue") cube([10,10,50]);

在此处输入图像描述

4

1 回答 1

5

translate 将一个对象从一个笛卡尔点“移动”到另一个。

translate 函数总是期望在他的第一个参数处有一个数组(名为 v,我们的 x、y 和 z 坐标的数组)。除非您确实使用不同的参数位置,否则可以在没有参数名称的情况下编写 openscad 中的任何函数调用。因此,以 translate 函数为例:

translate(0)
// ignored, first parameter is not an array.
cube([5,5,5]);

translate(v=5)
// ignored, v is not an array.
cube([5,5,5]);

translate([10,10,10])
// normal call.
cube([5,5,5]);

translate(v=[10,10,10])
// named parameter call.
cube([5,5,5]);

translate(1,2,3,4,5,6,7,8,9,0,infinite,v=[15,15,15])
// it works! we named the parameter, so 
// openscad doesn't care about it's position!
cube([5,5,5]);          

translate(1,2,3,4,5,6,7,8,9,0,[20,20,20])
// ignored, the first parameter is not an array
// AND v is not defined in this call!
cube([5,5,5]);          

// At this point there are 3 cubes at the same position
// and 3 translated cubes!

test();
test(1);
test(1,2);
test(1,2,3);
test(1,2,3,4);


// 01) There is no function overwrite in openscad (it doesn't care about the number of parameters to 
// 02) The function names are resolved at compile time (only the last one will be recognized).
module test(p1,p2,p3)   echo( "test3" );
module test(p1,p2)      echo( "test2" );
module test(p1)         echo( "test1" );

OpenScad 在任何地方都使用这种语法,不仅在 translate 函数调用中。

现在你的两行:

translate([5,5,-25])      // executed, cube moved to x=5,y=5,z=-25
    color("red")          // executed
        cube([10,10,50]); // executed, default creation pos x=0,y=0,z=0

translate(5,5,-25)        // ignored, cube not moved.
    color("blue")         // executed
        cube([10,10,50]); // executed, default creation pos x=0,y=0,z=0
于 2013-07-03T22:57:52.907 回答