3D 海龜繪圖

March 14, 2022

t3d 函式

``````use <polyline_join.scad>
use <turtle/t3d.scad>

angle = 144;
length = 10;
n = 5;
width = 1;
commands = [["turn", angle], ["forward", length]];

module repeat(t, commands, n, width) {
if(n > 0) {
new_t = t3d(t, commands);
polyline_join([t3d(t, "point"), t3d(new_t, "point")])
sphere(width / 2);
repeat(new_t, commands, n - 1, width);
}
}

t = t3d();
for(a = [0:360/n:360]) {
repeat(t3d(t, [["pitch", a]]), commands, n, width);
}
``````

footprints3 函式

`t2d` 有個對應的 `footprints2` 函式，`t3d` 也有個對應的 `footprints3` 函式，它只接受 `"forward"``"turn"``"roll"``"pitch"` 指令，函式會自動生成、管理海龜，如果你只是單純地想讓海龜前進、轉彎、翻身、抬頭，記錄海龜走過的路徑，使用 `footprints3` 會簡單許多。例如：

``````use <polyline_join.scad>
use <turtle/footprints3.scad>

angle = 144;
length = 10;
n = 5;
width = 1;

commands = [
for(i = [0:n])
each [["turn", angle], ["forward", length]]
];

for(a = [0:360/n:360]) {
path = footprints3([["pitch", a], each commands]);
polyline_join(path)
sphere(width / 2);
}
``````

``````use <polyline_join.scad>
use <turtle/footprints3.scad>

length = 10;
width = 2;
n = 200;

\$fn = 24;

turn_a = 360 / \$fn;
pitch_a = 5;

path = footprints3([
for(i = [0:n])
each [
["forward", length],
["turn", turn_a],
["pitch", pitch_a]
]
]);

polyline_join(path)
sphere(width / 2, \$fn = 4);
``````