Cylinder_array (count, distance, rows)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Cylinder_array (count, distance, rows)

Droidene
Hello everyone, im new to this forum and new to OpenSCAD program.
Awsome program.

First, i tried this:

cylinder_array(21,5) cylinder(r=2, h=10);

module cylinder_array( count, distance ){
    for ( i = [0:1:count-1] ){
        translate([distance*i,0,0])
        children();
    }
}

Then i wanted to copy that row into serveal rows.
I didn't had a clue and i did like this:

translate ([-0,0,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,5,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,10,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,15,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,20,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,25,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,30,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,35,0]) cylinder_array(21,5) cylinder(r=2, h=10);

module cylinder_array( count, distance ){
    for ( i = [0:1:count-1] ){
        translate([distance*i,0,0])
        children();
    }
}

Cool i was thinking, but knew there a better way of doing this. If im gonna make serveal of these the code will be long and messy. Not good.

Then i was thinking, hmm how?
I tried this:

cylinder_array(21,5,25) cylinder(r=2, h=10);

module cylinder_array( count, distance, rows ){
    for ( i = [0:1:count-1] ){
        for ( h = [0:1:rows-1]){
        translate([0,distance*i,0])
            translate([rows+distance*h,0,0])
        children();
        }
    }
}

Wow, i almost can taste it, much much less code but i dont think this is enterily correct either.
I see the whole thing moved away from origin: 0,0 .. why?
I know iv done something wrong here.

Anyone out there can help me a little on the road?
Reply | Threaded
Open this post in threaded view
|

Re: Cylinder_array (count, distance, rows)

nophead
It is translated from the origin because you added rows to distance * h.

Here is a corrected version with even less code:

cylinder_array(21,5,25) cylinder(r=2, h=10);

module cylinder_array( count, distance, rows )
    for (i = [0 : count - 1], h = [0 : rows-1])
        translate([distance * h, distance * i, 0])
            children();


On 25 June 2017 at 13:36, Droidene <[hidden email]> wrote:
Hello everyone, im new to this forum and new to OpenSCAD program.
Awsome program.

First, i tried this:

cylinder_array(21,5) cylinder(r=2, h=10);

module cylinder_array( count, distance ){
    for ( i = [0:1:count-1] ){
        translate([distance*i,0,0])
        children();
    }
}

Then i wanted to copy that row into serveal rows.
I didn't had a clue and i did like this:

translate ([-0,0,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,5,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,10,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,15,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,20,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,25,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,30,0]) cylinder_array(21,5) cylinder(r=2, h=10);
translate ([-0,35,0]) cylinder_array(21,5) cylinder(r=2, h=10);

module cylinder_array( count, distance ){
    for ( i = [0:1:count-1] ){
        translate([distance*i,0,0])
        children();
    }
}

Cool i was thinking, but knew there a better way of doing this. If im gonna
make serveal of these the code will be long and messy. Not good.

Then i was thinking, hmm how?
I tried this:

cylinder_array(21,5,25) cylinder(r=2, h=10);

module cylinder_array( count, distance, rows ){
    for ( i = [0:1:count-1] ){
        for ( h = [0:1:rows-1]){
        translate([0,distance*i,0])
            translate([rows+distance*h,0,0])
        children();
        }
    }
}

Wow, i almost can taste it, much much less code but i dont think this is
enterily correct either.
I see the whole thing moved away from origin: 0,0 .. why?
I know iv done something wrong here.

Anyone out there can help me a little on the road?



--
View this message in context: http://forum.openscad.org/Cylinder-array-count-distance-rows-tp21740.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Cylinder_array (count, distance, rows)

Droidene
Ahh of course, thank you.
It make all sense, awsome.