convert to loop?

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

convert to loop?

fred_dot_u
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

loop number	x	y	rotation
0		-v	-v	0
1		+v	-v	90
2		+v	+v	180
3		-v	+v	270
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.
Reply | Threaded
Open this post in threaded view
|

Re: convert to loop?

herdima
Use pow(-1, rcount)
Reply | Threaded
Open this post in threaded view
|

Re: convert to loop?

fred_dot_u
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?
Reply | Threaded
Open this post in threaded view
|

Re: convert to loop?

Richard Urwin
In reply to this post by herdima
Like this?

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();
}
Reply | Threaded
Open this post in threaded view
|

Re: convert to loop?

Richard Urwin
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();
}
Reply | Threaded
Open this post in threaded view
|

Re: convert to loop?

fred_dot_u
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.