translate()与多个参数有什么关系?

Mar*_*son 2 openscad

我不小心在翻译向量中省略了方括号.OpenSCAD默认忽略了错误,而不是导致错误.

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

translate([5,5,-25]) color("red") cube([10,10,50]);
translate(5,5,-25) color("blue") cube([10,10,50]);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ago*_*ost 5

翻译将一个物体从一个笛卡尔点"移动"到另一个笛卡尔点.

translate函数总是期望一个数组在他的第一个参数(名为v,具有我们的x,y和z坐标的数组).opencad中的任何函数调用都可以在没有参数名称的情况下编写,除非您使用不同的参数位置.因此,使用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" );
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

  • 不,这不是一个bug.看一下openscad [翻译文档](http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#translate) - 它不是显式的,但是translate需要一个数组.当你使用translate(0,0,-25)时,你实际上传递了3个参数,没有一个是数组.看看我的例子中的评论 - 我列举了一些案例.我同意你的意见,文档不清楚错误/异常情况下的行为,在任何地方都没有说明哪些错误会被忽略. (2认同)