prologues := 3;
outputtemplate := "%j/%j-%c.svg";
outputformat := "svg";
verbatimtex
%&latex
\documentclass{article}
\usepackage{amsmath}
\usepackage[charter]{mathdesign}
\begin{document}
etex
u:=2cm;
a:= 2u;
vardef proj(expr P,M,N) =
save H;
pair H;
H = whatever [M,N];
H - P = whatever * (M - N) rotated 90;
H
enddef;
path carre,cardioide;
carre = (0,0)--(1,0)--(1,1)--(0,1)--cycle;
for i:=0 upto 160:
beginfig(i);
path cercle,tangente,vec;
pair P,M,O,P';
pickup pencircle scaled 0.8;
drawarrow (-a,0)--(2a,0);
drawarrow (0,-a)--(0,a);
O:=(0,0);
pickup pencircle scaled 0.5;
cercle := fullcircle scaled a shifted (a/2,0);
draw cercle dashed evenly;
P = point (4-i/20) of cercle;
if i=0:
M = P;
cardioide = M;
fi;
if (i<>0) and (i<>80) and (i<>160):
P' = (xpart P +0.5*a, (xpart P +0.5*a)*((-xpart P)/(ypart P)+a/(2*(ypart P)))+a*(xpart P)/(2*(ypart P)));
tangente = 5[P,P']--5[P',P];
M = proj(O,P,P');
vec = 20[O,M]--20[M,O];
cardioide := cardioide..M;
pickup pencircle scaled 1;
drawarrow cardioide withcolor red;
pickup pencircle scaled 0.5;
draw carre scaled 12 rotated (angle(M-P)+180) shifted M dashed withdots scaled 0.3;
draw tangente withcolor blue dashed evenly;
draw vec withcolor blue dashed evenly;
dotlabel.urt(btex $M$ etex,M);
dotlabel.urt(btex $P$ etex,P);
fi;
if i=80 :
pickup pencircle scaled 1;
M:=P;
cardioide := cardioide..M;
draw cardioide withcolor red;
dotlabel.urt(btex $P$ etex,P);
fi;
if i=160 :
pickup pencircle scaled 1;
M:=P;
cardioide := cardioide..M;
draw cardioide withcolor red;
fi;
label.top(btex $a$ etex, (a/2,0));
label.llft(btex $x$ etex, (0.99*2a,0));
label.urt(btex $y$ etex, (0,0.9*a));
dotlabel.urt(btex $O$ etex,O);
label(btex $r=a(1+\cos\theta)$ etex,(3/2*a,a/2));
clip currentpicture to (-a,-a)--(2*a,-a)--(2*a,a)--(-a,a)--cycle;
endfig;
endfor;
end