的翻譯 「動作」 一個對象從一個笛卡爾點到另一個。
translate函數總是需要在他的第一個參數(名爲v,具有我們的x,y和z座標的數組)的數組中。 openscad中的任何函數調用都可以在不使用參數名稱的情況下編寫,除非您使用不同的參數位置。 因此,使用翻譯功能例如:
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([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
這就是我想爲好,但如果你真正嘗試它,'翻譯(0,0,-25)'似乎是一個空操作。將其更改爲'translate([0,0,-25])將按照預期的方式在z軸上移動對象-25。我已經更新了問題以顯示我得到的結果。 –
在我看來,在openscad中有一個bug。 'translate(0,0,-25)'應該和'translate([0,0,-25])'做同樣的事情,否則它應該會導致錯誤產生額外的參數。作爲一個實際的事情,現在我仔細尋找缺少'[]',當我看到一塊未按預期移動時。 –
不,不是一個錯誤。看看openscad [翻譯文檔](http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#translate) - 它不是顯式的,但翻譯需要一個數組。當你使用translate(0,0,-25)時,你實際上傳遞了3個參數而沒有一個是數組。看看我的例子中的評論 - 我列舉了幾個例子。我同意你的觀點,即在錯誤/例外的情況下,文件不清楚哪些行爲是錯誤的,在哪裏沒有說明哪些錯誤將被忽略。 – agodinhost