J'ai essayé de trouver la hauteur de l'image fixe (je pense que j'ai réussi...) et de l'animation (mais là j'ai bricolé et ça ne va pas
) pour calculer l'écart et trouver le décalage. Mais j'ai du mal à voir comment l'animation est placée par rapport à l'image fixe (alignée sur le haut, centrée, ... ?). Enfin, c'est beaucoup de bricolage, dommage car on y gagne vraiment en poids !
Code : Tout sélectionner
import graph_pi;
import animate;
settings.tex="pdflatex";
settings.outformat="pdf";
usepackage("fourier","upright");
real hbb, hbba1min, hbba1max, hbba2min, hbba2max, hbba3min, hbba3max, ha, diff;
real f(real x) {return cos(x);}
path Cf1=graph(f,0,pi,n=20,Hermite);//,n=400);
path Cf2=graph(f,-pi,pi,n=20,Hermite);//,n=400);
path Cf3=graph(f,pi,3pi,n=20,Hermite);//,n=400);
transform sc=scale(.8);
pen pinit=1.2bp+magenta, pf=1.2bp+.8blue, pvec=bp+deepgreen;
void trace(path f, pen p,
Label L="", real r=0, real per=2pi, pair NS=(0,0),
pen pv=nullpen, arrowbar arrow=Arrow(HookHead,2mm)){
draw(f,p);
if (NS!=(0,0))
draw(Label(sc*L,Fill(white),align=NS),(r,f(r))--(r+per,f(r+per)),pv,arrow);
}
graphicrules(xunit=1cm, yunit=1cm, xmin=-3pi, xmax=3pi, ymin=-1.5, ymax=1.5);
add(millimeterpaper(p=1bp+orange),(0,0));
labeloij(Lo=sc*"$O$", Li=sc*"$\overrightarrow{\imath}$", Lj=sc*"$\overrightarrow{\jmath}$");
cartesianaxis(xticks=Ticks(sc*Label(Fill(white)),
labelfrac(factor=pi,symbol="\pi",symbolin=true,zero=false),
Step=pi/2, ptick=black),
yticks=Ticks(sc*Label(Fill(white)),labelfrac(zero=false),Step=1,step=.5));
picture pic;
pic.add(currentpicture);// Sauvegarde de l'image fixe dans pic
hbb=max(pic).y-min(pic).y; //hauteur de l'image fixe
erase();
animation A;
// --------------------------------------------------------------------------
for (real p=-1; p<=1; p+=.1) {
save();
trace(Cf1,pinit);
draw(xscale(-p)*Cf1,pinit);
hbba1max=max(currentpicture).y; //
hbba1min=min(currentpicture).y;
A.add();
restore();
}
for (real t=0; t<=2pi; t+=pi/25) {
save();
trace(Cf2,pinit,"$2\pi \vec{\imath}$",.75,N,pvec);
draw(shift(t,0)*Cf2,pf);
hbba2max=max(currentpicture).y; //
hbba2min=min(currentpicture).y;
A.add();
restore();
}
for (real t=0; t<=2pi; t+=pi/25) {
save();
trace(Cf2,pinit,"$2\pi \vec{\imath}$",.75,N,pvec);
trace(Cf3,pf,"$-2\pi \vec{\imath}$",-pi,-2pi,S,pvec);
draw(shift(-t,0)*Cf2,pf);
hbba3max=max(currentpicture).y; //
hbba3min=min(currentpicture).y;
A.add();
restore();
}
add(pic);
ha=max(hbba1max,hbba2max,hbba3max)-min(hbba1min,hbba2min,hbba3min); //hauteur animation
diff=(hbb-ha)/2; // Calcul du décalage
label(A.pdf(delay=100,"controls"),(0,-diff/cm));