Arbre en 3 dimensions
I. Arbre simple
restart:
with( plots):
# **** outils vectoriels *****
mult:=proc(fac,M) map(x ->fac*x,M) end:
pvect:=proc(a,b) [a[2]*b[3]-a[3]*b[2],b[1]*a[3]-a[1]*b[3],a[1]*b[2]-a[2]*b[1]] end:
scal:=proc(a,b) add(a[i]*b[i],i=1..nops(a)) end:
norme:=proc(a) local b: b:=eval(a): evalf(sqrt(add(b[i]^2,i=1..nops(b)))) end:
rot:=proc(axe,t,point) # rotation
local axe1:
axe1:=mult(1/norme(axe),axe):
mult(cos(t),point) + mult(sin(t),pvect(axe1,point)) +
mult((1-cos(t))*scal(axe1,point),axe1):
end:
#******************************
arbre:=proc(A,B,L,t,ang,n)
local k,M;
k:=nops(L):
if n>0 then
M:=[ seq(rot(pvect(B-A,[0,1,0]),
evalf(t[q]), evalf(L[q])*(B-A)) ,q=1..k)]:
[A,B],seq(arbre(B,B+rot([0,0,1],evalf(2*ang[1+(n mod (k-1))]),
rot(M[2]-M[1],evalf(ang[q]), M[q] ) )
,L,t,evalf(ang),n-1), q=1..k)
else [A,B] fi
end:
# ***** nn nbre de niveau de branches ***************
# ****** nbre de branches partant d'un noeud est \303\251gal *****
#***** nops(coeffslong)=nops(angA)=nops(angB) ***********
nn:=6;
coeffslong:=[0.7,0.8,0.75]: # coeffslong:= [0.7,0.8,0.75,0.7]: # 4branches
angA:=[Pi*0.2,0,-0.3*Pi] : # angA:=[Pi*0.2,0,-0.3*Pi,Pi*0.1]
angB:=[Pi*0.2,-Pi*0.18,Pi*0.12]: # angB:=[Pi*0.2,-Pi*0.18,Pi*0.12,Pi*0.1]
graf:=[arbre([0,0,0],[0,0,1],coeffslong,angA,angB,nn)]:
graf:=op(map(y ->map(z->convert(z,list),y),graf)):
# ********** trac\303\251 de l'arbre ********
plotsetup(inline):
gr:=PLOT3D(CURVES(graf),AXESSTYLE(NONE),SCALING(CONSTRAINED),THICKNESS(2),ORIENTATION(70,75)):
gr;
plotsetup(inline):
II. Animation
# ************* animation ***********
tot:=nops([graf]):
gr:=display([seq(display(PLOT3D(CURVES(graf[1..iquo(tot,20)*k]))),k=1..20),PLOT3D(CURVES(graf))],axes=none,scaling=constrained,insequence=true,orientation=[0,75],title="animation",thickness=2):
gr;
plotsetup(inline):
III. Arbre 3 D
# **** en 3D ( n < 7 sinon tr\303\250s long ) *************
# faire effectuer arbre simple avant
tube:=proc(A,n,nn) tubeplot(mult((1-t),A[1])+mult(t,A[2]),t=0..1,radius=0.1/(t+n)^1.1,grid=
[3,20],color=COLOR(RGB,(1-n/nn)*.55,(1-n/nn)*.2+n/nn*0.7,0.05))
end:
NB:=nops(coeffslong);
LL:= [seq(i,i=1..nn+1 )]:
for i from nn+1 to 2 by (-1) do LL:=[op(LL),seq( op(LL[i..nops(LL)]),k=1..NB-1)] od:
LL:=[op(LL[1..nn]),op(LL[nn+1..nops(LL)])]:
plotsetup(inline):
plotsetup(window):
gr:=display3d(seq(tube(graf[k],LL[k],nn),k=1..nops([graf])),#[graf]
scaling=constrained,style=patchnogrid,lightmodel=light2,orientation=[40,80]):
gr;
plotsetup(inline):
Autre arbre
restart:
# **** outils vectoriels *****
mult:=proc(fac,M) map(x ->fac*x,M) end:
pvect:=proc(a,b) [a[2]*b[3]-a[3]*b[2],b[1]*a[3]-a[1]*b[3],a[1]*b[2]-a[2]*b[1]] end:
scal:=proc(a,b) add(a[i]*b[i],i=1..nops(a)) end:
norme:=proc(a) local b: b:=eval(a): evalf(sqrt(add(b[i]^2,i=1..nops(b)))) end:
simil:=proc(r,axe,t,listepts) # similitude
local axe1:
axe1:=mult(1/norme(axe),axe):
map( u -> mult(r*cos(t),u) + mult(r*sin(t),pvect(axe1,u)) +
mult(r*(1-cos(t))*scal(axe1,u),axe1),listepts):
end:
# **** outils vectoriels *****
DEPART:=[[[0,0,0],[0,0,1]]]:
arbre:=proc(coefs,axes,angs,n)
local i, tamp, alea,val; global DEPART:
if n = 1 then DEPART ;
else
alea:=rand(1..2*n): val:=alea():
tamp:=[seq( op(map( w -> simil(coefs[i],subs(t=val*Pi/12,axes[i]),angs[i],w),
arbre( coefs,axes,angs,n-1))), i=1..nops(coefs))]:
tamp:=map( w -> map( u -> [0,0,1]+u,w),tamp) :
tamp:=evalf([op(DEPART),op(tamp)]):
tamp;
fi:
end:
facteur:=proc(n)
if n=1 then [1]
else [n,seq(op(facteur(n-1)),i=1..3)]
fi;
end:
tube:=proc(A,n,nn)
#print(mult((1-t),A[1])+mult(t,A[2]));
tubeplot(mult((1-t),A[1])+mult(t,A[2]),t=0..1,radius=0.1/(t+n)^1.05,
grid=[3,20],style=patchnogrid,
color=COLOR(RGB,(1-n/nn)*0.8,(1-n/nn)*.4+(n+1)/nn*0.7,0.0)):
end:
with(plots):
coeffslong:=[0.8,0.7,0.65]:
angles:=[Pi*0.2,+Pi*0.15,Pi*0.3]:
axes:=[seq([cos(t+2*Pi/3*k),sin(t+2*Pi/3*k),0],k=0..2)]:
# t pour faire tourner et avoir un arbre irr\303\251gulier
n:=8;
AA:=arbre(coeffslong,axes,angles,n):
co:=facteur(n):
#PLOT3D(CURVES(op(AA),COLOR(RGB,0,0,1)),SCALING(CONSTRAINED),ORIENTATION(20,90));
plotsetup(window):
gr:=display([seq(tube(AA[i],n+1-co[i],n+1),i=1..nops(AA))],scaling=constrained,orientation=[45,80],lightmodel=light2):
gr;
plotsetup(inline):