discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

How can i use multimatrix

U
ufomorace
Thu, Aug 20, 2015 8:39 PM

i wish to chain cubes end to end inside a loop, so that i can construct a
spiral made of cubes only using dynamic rules of how they are added together
rather than a parametric equation. i.e. translate 1, tilt 20', rotate-z
10'... would make a 3d spirograph.

Here is an example file using openscad recursion (which memory-crashes very
fast compared to openscad loops) i wish to do the same using a loop? i am
confused.

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); 

Is it possible at all, if i cannot change the multimatrix variable, to
iterate it progressively in a loop?

--
View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

i wish to chain cubes end to end inside a loop, so that i can construct a spiral made of cubes only using dynamic rules of how they are added together rather than a parametric equation. i.e. translate 1, tilt 20', rotate-z 10'... would make a 3d spirograph. Here is an example file using openscad recursion (which memory-crashes very fast compared to openscad loops) i wish to do the same using a loop? i am confused. 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); Is it possible at all, if i cannot change the multimatrix variable, to iterate it progressively in a loop? -- View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570.html Sent from the OpenSCAD mailing list archive at Nabble.com.
TP
Torsten Paul
Thu, Aug 20, 2015 9:06 PM

On 08/20/2015 10:39 PM, ufomorace wrote:

Is it possible at all, if i cannot change the multimatrix variable, to
iterate it progressively in a loop?

You could generate the list of matrices in a recursive function first
and use the result in a for() module to generate the actual geometry.

// 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]);

ciao,
Torsten.

On 08/20/2015 10:39 PM, ufomorace wrote: > Is it possible at all, if i cannot change the multimatrix variable, to > iterate it progressively in a loop? > You could generate the list of matrices in a recursive function first and use the result in a for() module to generate the actual geometry. // 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]); ciao, Torsten.
U
ufomorace
Thu, Aug 20, 2015 11:31 PM

Thanks, I was scratching around in the dunes of code land all day in the hope
of finding some vague mirage of of binary hope to ogle at, and suddenly this
lightning code arrives:)

It's the same kind of geometry process as used in Structuresynth.

Why do the cubes tilt on edge and can i make them tilt trough the middle?
http://forum.openscad.org/file/n13572/tilt.jpg

--
View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13572.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks, I was scratching around in the dunes of code land all day in the hope of finding some vague mirage of of binary hope to ogle at, and suddenly this lightning code arrives:) It's the same kind of geometry process as used in Structuresynth. Why do the cubes tilt on edge and can i make them tilt trough the middle? <http://forum.openscad.org/file/n13572/tilt.jpg> -- View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13572.html Sent from the OpenSCAD mailing list archive at Nabble.com.
N
Neon22
Fri, Aug 21, 2015 9:33 AM

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

--
View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13575.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

for (m = matrices(17)) multmatrix(m) cube([5, 10, 5], center=true); -- View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13575.html Sent from the OpenSCAD mailing list archive at Nabble.com.
U
ufomorace
Sat, Aug 22, 2015 6:24 PM

Thanks Neon22 i will see the anandamide version.

I had a go to rotate from centre=true, it sets the rotation point at the
gravity centre of the cube.

Checked the forums for a solution, in the end i wrote a new cube primitive
that rotates ok.

I don't know structure synth very well but i have a grasp of the geometry
process as i have written a small copycat program of it enough to know some
of the iteration rules...

It would have been difficult to write the same thing in openscad without
adding multimatrix in a loop for some 1000ds of transforms, and if it's
possible then you can take the above code and create some angle behaviour
rules and sizing rules to make s-synth tentacles. The actual language of the
SS is not necessary, just to copy it's iteration process which is adding
things on top of each other and rotating them, and adding functions that
make systems of loops in a code spagetti of cubes. when making geometry with
loops it's best to have an underlying ruleset that makes the angles regular
and all the things in a sequence, the above code does that ok.

I am having problems with the rotation matrix though, it's too good, i
realized my other program has an error that flips around over 180 and makes
spirographs and i have no idea how to recreate it in openSCAD.

--
View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13593.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Thanks Neon22 i will see the anandamide version. I had a go to rotate from centre=true, it sets the rotation point at the gravity centre of the cube. Checked the forums for a solution, in the end i wrote a new cube primitive that rotates ok. I don't know structure synth very well but i have a grasp of the geometry process as i have written a small copycat program of it enough to know some of the iteration rules... It would have been difficult to write the same thing in openscad without adding multimatrix in a loop for some 1000ds of transforms, and if it's possible then you can take the above code and create some angle behaviour rules and sizing rules to make s-synth tentacles. The actual language of the SS is not necessary, just to copy it's iteration process which is adding things on top of each other and rotating them, and adding functions that make systems of loops in a code spagetti of cubes. when making geometry with loops it's best to have an underlying ruleset that makes the angles regular and all the things in a sequence, the above code does that ok. I am having problems with the rotation matrix though, it's too good, i realized my other program has an error that flips around over 180 and makes spirographs and i have no idea how to recreate it in openSCAD. -- View this message in context: http://forum.openscad.org/How-can-i-use-multimatrix-tp13570p13593.html Sent from the OpenSCAD mailing list archive at Nabble.com.