0

ループ内で立方体を端から端まで連鎖させて、パラメトリック方程式ではなく、それらを一緒に追加する方法の動的ルールのみを使用して、立方体で構成されるスパイラルを構築できるようにします。つまり、translate 1、tilt 20'、rotate-z 10'... で 3D スピログラフが作成されます。

これは、openscad 再帰を使用したサンプル ファイルです (openscad ループに比べてメモリ クラッシュが非常に高速です)。ループを使用して同じことをしたいですか? 私は混乱しています。

levels = 50; // number of levels for the recursion

len = 100; // length of the first segment
thickness = 5; // thickness of the first segment

// the identity matrix
identity = [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];

// random generator
function rnd(s, e) = rands(s, e, 1)[0];

// generate 4x4 translation matrix
function mt(x, y) = [ [ 1, 0, 0, x ], [ 0, 1, 0, y ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];

// generate 4x4 rotation matrix around Z axis
function mr(a) = [ [ cos(a), -sin(a), 0, 0 ], [ sin(a), cos(a), 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ];

module tree(length, thickness, count, m = identity) {
    color([0, 1 - (0.8 / levels * count), 0])
        multmatrix(m)
            cube([thickness, length, thickness]);

    if (count > 0) {
        tree( length, thickness, count - 1, m * mt(0, length) * mr(31.4159));

    }
}

tree(len, thickness, levels);
4

1 に答える 1

0

最初に再帰関数で行列のリストを生成し、その結果を for() モジュールで使用して実際のジオメトリを生成できます。

// the identity matrix 
identity = [ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]; 

// generate 4x4 rotation matrix around Z axis 
function mr(a) = [ [ cos(a), -sin(a), 0, 0 ], [ sin(a), cos(a), 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]; 

// generate 4x4 translation matrix 
function mt(x, y) = [ [ 1, 0, 0, x ], [ 0, 1, 0, y ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]; 

function matrices(i = 10, m = identity, ret = []) = i >= 0 
        ? matrices(i - 1, m * mt(0, 10) * mr(20), concat(ret, [ m ])) 
        : ret; 

for (m = matrices(17)) 
  multmatrix(m) 
    cube([5, 10, 5]); 

Torsten Paul の助けを借りて。

于 2015-08-21T05:16:57.910 に答える