openscad 入門教程 - 繪製小車

這個是官方教程的一個理解,代碼也是 官方教程第一章 的內容.

大概思想就是畫兩個立方體,然後再來四個輪子,兩個棍子,搞出一個小車的模型.

下面是代碼實現:
在這裏插入圖片描述
下面的代碼就粘貼到左邊的代碼粘貼區, 然後按F5或者F6運行代碼,就可以看到中間3D模型的展示區域的3D模型了.

爲了減小電腦的運行負擔,可以在 菜單欄中選擇 view -> wireframe (快捷鍵 F11)選擇棍棒模型,這個在大型項目中可能比較實用,

$fa = 1;
$fs = 0.4;
cube([60,20,10],center=true);
translate([5,0,10 - 0.001])
    cube([30,20,10],center=true);
translate([-20,-15,0])
    rotate([90,0,0])
    cylinder(h=3,r=8,center=true);
translate([-20,15,0])
    rotate([90,0,0])
    cylinder(h=3,r=8,center=true);
translate([20,-15,0])
    rotate([90,0,0])
    cylinder(h=3,r=8,center=true);
translate([20,15,0])
    rotate([90,0,0])
    cylinder(h=3,r=8,center=true);
translate([-20,0,0])
    rotate([90,0,0])
    cylinder(h=30,r=2,center=true);
translate([20,0,0])
    rotate([90,0,0])
    cylinder(h=30,r=2,center=true);

代碼中,我們看到涉及到關鍵詞有

函數名 意義
cube 繪製矩形
translate 3維移動
rotate 3維旋轉
cylinder 繪製圓柱體

在openscad中, cube,cylinder 這些就是實體, 可以通過 rotate, color 和 translate 這些來修飾.

第一行和第二行是 特定變量,用來指定生成模型的分辨率:

$fa = 1;
$fs = 0.4;

另外記得,每個完整的語句要用分號結束,實體後有一個分號!

另外,開源社區在召集小夥伴做軟件翻譯,大家基極響應.
https://github.com/yjwork-cn/translate/blob/master/openscad.po


參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章