%@ illustration décomposition en série de fourier
%@ Maxime Chupin
%@ 4 janvier 2017
verbatimtex
%&latex
\documentclass{article}
\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\begin{document}
etex
prologues := 3;
outputtemplate := "svg/%j-%c.svg";
outputformat := "svg";
input mpcolornames
% unité
u := 1cm;
pi := 3.141592653589793;
marge := u;
% taille de la décomposition
n := 4;
% taille de la fenêtre de tracé
numeric tailleclip;
tailleclip := u*(2.0*pi);
% coefficients
numeric coef[];
% phase
numeric phi[];
% on affecte les valeur
coef[0] := u*4.0/pi;
coef[1] := u*4.0/3.0/pi;
coef[2] := u*4.0/5.0/pi;
coef[3] := u*4.0/7.0/pi;
phi[0] := 1.0;
phi[1] := 3.0;
phi[2] := 5.0;
phi[3] := 7.0;
% les tracés
path decomp[];
decomp[0] := (0,0);
decomp[1] := (0,0);
decomp[2] := (0,0);
decomp[3] := (0,0);
path cercles[];
cercles[0] := fullcircle scaled (2.0*coef[0]);
cercles[1] := fullcircle scaled (2.0*coef[1]);
cercles[2] := fullcircle scaled (2.0*coef[2]);
cercles[3] := fullcircle scaled (2.0*coef[3]);
% les points sur les cercles
pair points[];
picture cliptrace[];
% le shift du clip
pair shiftclip;
% les traits horizontaux
path hori[];
% creneau
path creneau;
creneau := (0,-u)--(0,u) for i:=1 step 2 until 6: --(-u*i*pi,u)--(-u*i*pi,-u)--(-(i+1)*u*pi,-u)--(-(i+1)*u*pi,u)endfor ;
% couleurs
color couleurs[];
couleurs[0] := Tomato3;
couleurs[1] := PaleGreen4;
couleurs[2] := RoyalBlue3;
couleurs[3] := VioletRed2;
couleurs[4] := LavenderBlush4;
for theta := -360 upto 359:
if(theta >=0) :
beginfig(theta);
fi;
shiftclip := ((theta)*u/360*2.0*pi,0);
% les points
points[0] := coef[0]*(cosd(phi[0]*theta),sind(phi[0]*theta));
points[1] := coef[1]*(cosd(phi[1]*theta),sind(phi[1]*theta)) shifted points[0];
points[2] := coef[2]*(cosd(phi[2]*theta),sind(phi[2]*theta)) shifted points[1];
points[3] := coef[3]*(cosd(phi[3]*theta),sind(phi[3]*theta)) shifted points[2];
% les graphs
decomp[0] := decomp[0] -- (-(theta+360)*u/360*2.0*pi,ypart points[0]);
decomp[1] := decomp[1] -- (-(theta+360)*u/360*2.0*pi,ypart points[1]);
decomp[2] := decomp[2] -- (-(theta+360)*u/360*2.0*pi,ypart points[2]);
decomp[3] := decomp[3] -- (-(theta+360)*u/360*2.0*pi,ypart points[3]);
% on fabrique les images de la courbe qui avance
path clipcadre;
clipcadre := ((0,-1.5*marge)--(-tailleclip,-1.5*marge)--(-tailleclip,u/(2.0*pi)+1.5*marge)--(0,u/(2.0*pi)+1.5*marge)--cycle) shifted -shiftclip;
pickup pencircle scaled 2;
cliptrace[0] := image(
draw creneau withpen pencircle scaled 1 withcolor black dashed evenly withcolor couleurs[4];
draw decomp[0] withcolor couleurs[0];
clip currentpicture to clipcadre;
);
cliptrace[1] := image(
draw creneau withpen pencircle scaled 1 withcolor black dashed evenly withcolor couleurs[4];
draw decomp[1] withcolor couleurs[1];
clip currentpicture to clipcadre;
);
cliptrace[2] := image(
draw creneau withpen pencircle scaled 1 withcolor black dashed evenly withcolor couleurs[4];
draw decomp[2] withcolor couleurs[2];
clip currentpicture to clipcadre;
);
cliptrace[3] := image(
draw creneau withpen pencircle scaled 1 withcolor black dashed evenly withcolor couleurs[4];
draw decomp[3] withcolor couleurs[3];
clip currentpicture to clipcadre;
);
pickup pencircle scaled 1;
% on dessine les cercles avec rayons
picture clocks[];
clocks[0]:= image(
draw cercles[0];
draw (0,0) -- points[0];
);
clocks[1]:= image(
draw cercles[1];
draw (0,0) -- coef[1]*(cosd(phi[1]*theta),sind(phi[1]*theta));
);
clocks[2]:= image(
draw cercles[2];
draw (0,0) -- coef[2]*(cosd(phi[2]*theta),sind(phi[2]*theta));
);
clocks[3]:= image(
draw cercles[3];
draw (0,0) -- coef[3]*(cosd(phi[3]*theta),sind(phi[3]*theta));
);
% les tracés
draw cliptrace[0] shifted ((4.0*coef[0]+2*marge+tailleclip,0)+shiftclip);
draw cliptrace[1] shifted ((4.0*coef[0]+2*marge+tailleclip,-2.0*coef[0]-marge)+shiftclip);
draw cliptrace[2] shifted ((4.0*coef[0]+2*marge+tailleclip,-4.0*coef[0]-2*marge)+shiftclip);
draw cliptrace[3] shifted ((4.0*coef[0]+2*marge+tailleclip,-6.0*coef[0]-3*marge)+shiftclip);
% hack pour l'animation sur le web
fill ((-3*coef[0]-2marge,coef[0]+marge)--(-3*coef[0]-2marge,-7.0*coef[0]-4marge))--(4.0*coef[0]+2*marge,-7.0*coef[0]-4marge)--(4.0*coef[0]+2*marge,coef[0]+marge)--cycle withcolor white;
% les différents modes
draw clocks[0] withcolor couleurs[0];
draw clocks[1] shifted (0,-2.0*coef[0]-marge) withcolor couleurs[1];
draw clocks[2] shifted (0,-4.0*coef[0]-2*marge) withcolor couleurs[2];
draw clocks[3] shifted (0,-6.0*coef[0]-3*marge) withcolor couleurs[3];
% emboités
% première
draw clocks[0] shifted (2.0*coef[0]+marge,0) withcolor couleurs[0];
% deuxième
draw clocks[0] shifted (2.0*coef[0]+marge,-2.0*coef[0]-marge) withcolor couleurs[0];
draw clocks[1] shifted ((2.0*coef[0]+marge,-2.0*coef[0]-marge)+points[0]) withcolor couleurs[1];
% troisième
draw clocks[0] shifted (2.0*coef[0]+marge,-4.0*coef[0]-2*marge) withcolor couleurs[0];
draw clocks[1] shifted ((2.0*coef[0]+marge,-4.0*coef[0]-2*marge)+points[0]) withcolor couleurs[1];
draw clocks[2] shifted ((2.0*coef[0]+marge,-4.0*coef[0]-2*marge)+points[1]) withcolor couleurs[2];
% quatrième
draw clocks[0] shifted (2.0*coef[0]+marge,-6.0*coef[0]-3*marge) withcolor couleurs[0];
draw clocks[1] shifted ((2.0*coef[0]+marge,-6.0*coef[0]-3*marge)+points[0]) withcolor couleurs[1];
draw clocks[2] shifted ((2.0*coef[0]+marge,-6.0*coef[0]-3*marge)+points[1]) withcolor couleurs[2];
draw clocks[3] shifted ((2.0*coef[0]+marge,-6.0*coef[0]-3*marge)+points[2]) withcolor couleurs[3];
% les traits reliants les cercles au tracé
hori[0] := ((points[0]+(2.0*coef[0]+marge,0)) -- ((0, ypart points[0])+(4.0*coef[0]+2*marge,0))) ;
hori[1] := ((points[1]+(2.0*coef[0]+marge,-2.0*coef[0]-marge)) -- ((0, ypart points[1]-2.0*coef[0]-marge)+(4.0*coef[0]+2*marge,0))) ;
hori[2] := ((points[2]+(2.0*coef[0]+marge,-4.0*coef[0]-2*marge)) -- ((0, ypart points[2]-4.0*coef[0]-2*marge)+(4.0*coef[0]+2*marge,0))) ;
hori[3] := ((points[3]+(2.0*coef[0]+marge,-6.0*coef[0]-3*marge)) -- ((0, ypart points[3]-6.0*coef[0]-3*marge)+(4.0*coef[0]+2*marge,0))) ;
% dessine
draw hori[0] dashed evenly;
draw hori[1] dashed evenly;
draw hori[2] dashed evenly;
draw hori[3] dashed evenly;
% les coefficients
label(btex \Large $\dfrac{4}{\pi}\sin \theta$ etex, (-coef[0]-2marge,0));
label(btex \Large $+\dfrac{4}{3\pi}\sin 3\theta$ etex, (-coef[0]-2marge,-2.0*coef[0]-marge));
label(btex \Large $+\dfrac{4}{5\pi}\sin 5\theta$ etex, (-coef[0]-2marge,-4.0*coef[0]-2marge));
label(btex \Large $+\dfrac{4}{7\pi}\sin 7\theta$ etex, (-coef[0]-2marge,-6.0*coef[0]-3marge));
% barre verticale
draw ((0,coef[0]+marge)--(0,-7.0*coef[0]-4marge)) shifted (4.0*coef[0]+2*marge,0);
picture p_;
p_ =currentpicture;
draw ((-marge,-marge)+(llcorner p_))--((marge,-marge)+(lrcorner p_))--((marge,marge)+(urcorner p_))--((-marge,marge)+(ulcorner p_))--cycle withcolor white;
if(theta>=0):
endfig;
fi;
endfor
end.