[OpenSCAD] Why are recursive definitions slow ?

Ivo ivo.knutsel at gmail.com
Sun Apr 19 11:07:47 EDT 2015


I have the same object defined by recursive and by iteration. De iterative
definition is much faster on rendering.

Can someone provide some insight why this is ?

==== example ====

num=20;

module ring(){
  rotate_extrude() translate([10,0,0]) circle(r=2);    
}

module ring_r(count,maxcount,angle) {
  if (count<=maxcount) {
    ring();
    if ((count%4)==0)  
      rotate([0,0,angle]) translate([14,0,0]) rotate([90,0,0]) 
        ring_r(count+1,maxcount,angle);
    if ((count%4)==1)  
      rotate([0,angle,0]) translate([14,0,0]) rotate([90,0,0]) 
        ring_r(count+1,maxcount,angle);
    if ((count%4)==2)  
      rotate([0,0,-angle]) translate([14,0,0]) rotate([90,0,0]) 
        ring_r(count+1,maxcount,angle);
    if ((count%4)==3)  
      rotate([0,-angle,0]) translate([14,0,0]) rotate([90,0,0]) 
        ring_r(count+1,maxcount,angle);
  }
}

module iterative() {
for (i=[0:num-1])
  rotate([0,0,i*360/num])
    translate([40,0,0])
      rotate([0,i*90,0])
        scale([0.7,1,1])
          ring();
}

module nested() {

}

module recursive() {
  ring_r(0,19,18);
}

//iterative();
recursive(); 



--
View this message in context: http://forum.openscad.org/Why-are-recursive-definitions-slow-tp12427.html
Sent from the OpenSCAD mailing list archive at Nabble.com.




More information about the Discuss mailing list