discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

convert to loop?

F
fred_dot_u
Mon, Sep 12, 2016 2:31 PM

this segment is simple, even to me:

for (rcount = [0: 1: 3]){
rotate([0, 0, rcount * 90])
make something appear
}

the problem I'm hoping to solve involves translation of the "something"

the translation values for x and y for the four rotations above toggle
through positive and negative values

Is there a method to accomplish this in a single loop? I feel that if it has
to be accomplished in a nested loop, the four individual code segments
without a loop is just as easy to implement.

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

this segment is simple, even to me: for (rcount = [0: 1: 3]){ rotate([0, 0, rcount * 90]) make something appear } the problem I'm hoping to solve involves translation of the "something" the translation values for x and y for the four rotations above toggle through positive and negative values Is there a method to accomplish this in a single loop? I feel that if it has to be accomplished in a nested loop, the four individual code segments without a loop is just as easy to implement. -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373.html Sent from the OpenSCAD mailing list archive at Nabble.com.
H
herdima
Mon, Sep 12, 2016 3:42 PM

Use pow(-1, rcount)

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18374.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Use pow(-1, rcount) -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18374.html Sent from the OpenSCAD mailing list archive at Nabble.com.
F
fred_dot_u
Mon, Sep 12, 2016 3:54 PM

That is an interesting approach. It provides for a single value through the
loop, toggling from positive to negative, but how to use the same loop
variable (rcount) to provide for the non-toggling aspect of the second
coordinate of the translate command?

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18375.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

That is an interesting approach. It provides for a single value through the loop, toggling from positive to negative, but how to use the same loop variable (rcount) to provide for the non-toggling aspect of the second coordinate of the translate command? -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18375.html Sent from the OpenSCAD mailing list archive at Nabble.com.
RU
Richard Urwin
Mon, Sep 12, 2016 5:12 PM

Like this?

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18376.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Like this? -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18376.html Sent from the OpenSCAD mailing list archive at Nabble.com.
RU
Richard Urwin
Mon, Sep 12, 2016 5:17 PM

Mailing list doesn't like raw text? Here it is again.

module pointer()
{
polygon(points=[[1,0], [-1,0.5], [-1,-0.5]], paths=[[0,1,2,]],
convexity = 1);
}

v = 10;
xtran=[-v, v, v, -v];
ytran=[-v, -v, v, v];
rot = [0,90,180,270];

pointer();
for (i = [0:3])
{
echo(i, xtran[i], ytran[i], rot[i]);
translate([xtran[i], ytran[i],0]) rotate (rot[i],0,0)
pointer();
}

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18377.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Mailing list doesn't like raw text? Here it is again. module pointer() { polygon(points=[[1,0], [-1,0.5], [-1,-0.5]], paths=[[0,1,2,]], convexity = 1); } v = 10; xtran=[-v, v, v, -v]; ytran=[-v, -v, v, v]; rot = [0,90,180,270]; pointer(); for (i = [0:3]) { echo(i, xtran[i], ytran[i], rot[i]); translate([xtran[i], ytran[i],0]) rotate (rot[i],0,0) pointer(); } -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18377.html Sent from the OpenSCAD mailing list archive at Nabble.com.
F
fred_dot_u
Mon, Sep 12, 2016 5:56 PM

That's beautiful! I've learned a few new things, such as making use of an
array with pointers. I hope I can remember enough to make use of this
information in the future.
thank you very much for your assistance.

--
View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18378.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

That's beautiful! I've learned a few new things, such as making use of an array with pointers. I hope I can remember enough to make use of this information in the future. thank you very much for your assistance. -- View this message in context: http://forum.openscad.org/convert-to-loop-tp18373p18378.html Sent from the OpenSCAD mailing list archive at Nabble.com.