how to use an accumulating variable January 20, 2016 11:16AM |
Registered: 10 years ago Posts: 782 |
Re: how to use an accumulating variable January 21, 2016 03:58PM |
Registered: 11 years ago Posts: 369 |
translate([0,0,0]) cylinder(d=holdupdia, h=holdupht); //I'm assuming acc = 0 at this point //acc=acc+holdht; translate([0,0,holdht]) cylinder(d=holdshaftdia, h=holdshaftupperht); //acc=acc+holdshaftupperht; translate([0,0,holdht+holdshaftupperht]) cylinder(d=holdmiddia, h=holdmidht); //acc=acc+holdmidht; translate([0,0,holdht+holdshaftupperht+holdmidht]) cylinder(d=holdshaftdia, h=holdshaftmidht);
Re: how to use an accumulating variable January 21, 2016 05:03PM |
Registered: 10 years ago Posts: 782 |
Re: how to use an accumulating variable January 23, 2016 04:50AM |
Registered: 10 years ago Posts: 590 |
multicyl([[holdupdia,holdupht],[holdshaftdia,holdshaftupperht],[holdmiddia,holdmidht],[holdshaftdia,holdshaftmidht]]);I also included multicone() which allows the same kind of stacking for cones:
// stack of multiple cylinders defined by an array of [d,h] entries module multicyl( dh , index=0) { if(len(dh)>index){ cylinder(d=dh[index][0],h=dh[index][1]); translate([0,0,dh[index][1]])multicyl(dh,index+1); } } // stack of multiple cones defined by an array of [r1,r2,d] entries module multicone( rrh , index=0) { if(len(rrh)>index){ cylinder(r1=rrh[index][0],r2=rrh[index][1],h=rrh[index][2]); translate([0,0,rrh[index][2]])multicone(rrh,index+1); } } translate([0,-30,0]) multicyl(dh=[[50,2],[20,10],[30,5],[10,11],[50,3]]); translate([0,30,0]) multicone(rrh=[[25,25,2],[25,20,10],[20,10,5],[10,10,11],[20,22,3]]);And here the output of OpenScad for the above example:
Re: how to use an accumulating variable January 24, 2016 01:13PM |
Registered: 10 years ago Posts: 782 |
Re: how to use an accumulating variable January 25, 2016 05:11AM |
Registered: 11 years ago Posts: 369 |
Quote
appjaws1
Thank you, I think this is the only solution. Use arrays, but the problem is that they are difficult to change.
What is so hard to include a=a+1 in the openscad language?