I want to generate a self-similar, size-reduced, fixed-angle branching structure in OpenScad. The generated tree would simulate the lungs.
I managed to generate the first divisions ("generations") of the tree but I am stuck if I want to go further...
h = 0.79;
angle = 30;
diametreTubeBase = 13.5;
diametreTube = diametreTubeBase * 0.8 * 0.8; // deux niveau plus bas
diametreSphere = diametreTube*0.75;
rayonGrappe = 2.25*diametreSphere;
hFermeture = 3 ;
diamAimant = 4 + 0.2; // 0.2 pour l'épaisseur du matériel lors de l'impression
hAimant = 2 + 1;
resol = 18;
difference()
{
union(){
// 1ere génération
difference()
{
cylinder(h=rayonGrappe*1.5, d=diametreTube, center=false, $fn=resol);
{
translate([0,0,rayonGrappe*1.5 - hAimant])
cylinder(h=hAimant+1, d=diamAimant, center=false, $fn=resol);
}
}
for(i = [2,3]){
for(j = [1,pow(2,i-1)]){
echo(pow(-1,j));
translate([0,pow(-1,j)*(i-2)*sin(angle)*rayonGrappe*1.5*pow(h,i-2),-(i-2)*cos(angle)*rayonGrappe*1.5*pow(h,i-2)]){
rotate(a=[180,pow(-1,j)*angle,(i-2)*90+pow(-1,i)*90]){
cylinder(h=rayonGrappe*1.5*pow(h,i-1), d=diametreTube*pow(h,i-1), center=false, $fn=resol);
}
}
}
}
}
}
I expect that I would be able to generate the other generations with fixed angle division (30°) and rotation of 90 compared with the previous axis.
Thanks you for your insights.
That's going to be pretty challenging in raw openscad. Since this is a broad question I'm going to give a broad answer. The way I see it there are 3 different approaches you could take.
You could use relativity.scad. It makes it easier to position objects relative to other objects.
You could use recursive modules. They're plain openscad, no weird libraries, and probably the cleanest solution. They are going to require you to actually think about what you're doing though.
Finally, when all else fails, I drop down into solidpython and just make it work. There's not a lot you can't make work when you're using a general purpose programming language instead of openscad's limited markup.