# Source : geometrie2.mp

geometrie2.mp
```vardef linkpdf@#(expr s,z,pdf,c) =%Sert à mettre des liens entre fichiers PDF
picture p;
p := thelabel@#(s,z);
special "[ /Rect [ " & decimal xpart llcorner p & " " &
decimal ypart llcorner p & " " &
decimal xpart urcorner p & " " &
decimal ypart urcorner p & " ] " &
"/Border [ 0 0 0 ] " &
"/Action /GoToR /File (" & pdf & ") " &
draw p withcolor c;
enddef;
def projete(expr p,q,r)=
begingroup
save \$;
pair \$;
\$=whatever[q,r];
(\$-p) rotated 90 shifted q=whatever[q,r];
\$
endgroup
enddef;
def orthocentre(expr p,q,r )=%(sommet-côté opposé)
begingroup
save \$;
pair \$;
(\$-p) rotated 90=whatever*(r-q);
(\$-q) rotated 90=whatever*(p-r);
\$
endgroup
enddef;
def milieu(expr p,q)=
begingroup
save \$;
pair \$;
\$=1/2[p,q];
\$
endgroup
enddef;
def gravite(expr p,q,r)=%3 sommets
begingroup
save \$;
pair \$;
\$=2/3[p,milieu(q,r)];
\$
endgroup
enddef;
def inscrit(expr p,q,r)=%Sommets
begingroup
save \$,a,c;
pair \$;
numeric a,c;
a=(angle(p-r)-angle(q-r))/2;
c=(angle(r-q)-angle(p-q))/2;
(\$-r) rotated a shifted r=whatever[p,r];
(\$-q) rotated c shifted q=whatever[q,r];
\$
endgroup
enddef;
def circonscrit(expr p,q,r)=
begingroup
save \$;
pair \$;
(\$-1/2[p,q]) rotated 90 shifted p=whatever[p,q];
(\$-1/2[q,r]) rotated 90 shifted q=whatever[q,r];
\$
endgroup
enddef;
def cercle(expr p,q)=%centre-rayon
begingroup
save \$;
path \$;
\$=fullcircle scaled (2*q) shifted p;
\$
endgroup
enddef;
vardef droite(expr a,b,n)=%Points-"longueur"
save \$;
path \$;
\$=n[b,a]--n[a,b];
\$
enddef;
def demidroite(expr a,b,n)=%points [ab) - "longueur"
begingroup
save \$;
path \$;
\$=a--n[a,b];
\$
endgroup
enddef;
def symc(expr p,q)=%point-centre
begingroup
save \$;
pair \$;
\$=2[p,q];
\$
endgroup
enddef;
def syma(expr p,q,r)=%point-droite
begingroup
save \$;
pair \$;
\$=symc(p,projete(p,q,r));
\$
endgroup
enddef;
def codeang(expr p,q,r,n)=%point-sommet-point(sens direct)-rayon du codage
begingroup
save \$,codage,b,c,seg,sege;
picture \$;
\$=currentpicture;
path codage,seg,sege;%cercle pour le codage
pair b,c;
codage=cercle(q,(2*n));
seg=p--q;
sege=r--q;
numeric d,e;
b=codage intersectionpoint seg;
c=codage intersectionpoint sege;
d=angle(b-q)*((length codage)/360);
e=((length codage)/360)*angle(c-q);
if ((d>0) and (e>0)):
draw subpath(d,e) of codage;
fi
if ((d>0) and (e<0)):
draw subpath(d,(length codage)+e) of codage;
fi
if ((d<0) and (e>0)):
draw subpath((length codage)+d,(length codage)+e) of codage;
fi
if ((d<0) and (e<0)):
draw subpath((length codage)+d,(length codage)+e) of codage;
fi
if e=0 :
if d>0 :
draw subpath(0,d) of codage;
else:
draw subpath(d,0) of codage;
fi;
fi
if d=0 :
if e>0 :
draw subpath(0,e) of codage;
else:
draw subpath(e,0) of codage;
fi;
fi
\$
endgroup
enddef;
def para(expr p,q,r,n)=%pt-droite-longueur droite
begingroup
save \$;
path \$;
\$=droite(q,r,n) shifted (p-q);
\$
endgroup
enddef;
def codemil(expr p,q,n) =%extrêmités-angle de codage
begingroup
save \$,a,b,c,d;
path \$;
pair a,b,c,d;
a=milieu(p,q);
b=(a+2*unitvector(q-p))-(a-2*unitvector(q-p));
c=b rotated n shifted a;
d=symc(c,a);
\$=c--d;
\$
endgroup
enddef;
def codesegments(expr p,q,r,s,n)=%extrémités des segments
begingroup
save \$,v,w;
picture \$;
\$=currentpicture;
if n=5 :
draw fullcircle scaled 0.1cm shifted milieu(p,q);
draw fullcircle scaled 0.1cm shifted milieu(r,s);
fi
if n=4 :
pair v,w;
v=milieu(p,q);
w=milieu(r,s);
draw codemil(p,q,60);
draw codemil(p,q,120);
draw codemil(r,s,60);
draw codemil(r,s,120);
fi;
if n=3 :
draw codemil(p,q,60);
draw codemil(p,q,60) shifted (2*unitvector(p-q));
draw codemil(p,q,60) shifted (2*unitvector(q-p));
draw codemil(r,s,60);
draw codemil(r,s,60) shifted (2*unitvector(r-s));
draw codemil(r,s,60) shifted (2*unitvector(s-r));
fi;
if n=2 :
draw codemil(p,q,60) shifted unitvector(p-q);
draw codemil(p,q,60) shifted unitvector(q-p);
draw codemil(r,s,60) shifted unitvector(r-s);
draw codemil(r,s,60) shifted unitvector(s-r);
fi;
if n=1 :
draw codemil(p,q,60);
draw codemil(r,s,60);
fi;
\$
endgroup
enddef;
def mediatrice(expr p,q,n,m,o)=%extrémités-longueur-codage-options
begingroup
save \$,d;
picture \$;
pair d;
if o=0 :
drawoptions(dashed evenly);
fi
d=milieu(p,q);
\$=currentpicture;
draw perp(d,p,q,n);
draw codesegments(p,d,d,q,m);
\$
endgroup
enddef;
def segment(expr p,q) =%extrêmité
begingroup
save \$,b,c,d;
picture \$;
pair b,c,d;
b=3*unitvector(q-p);
c=b rotated 90 shifted p;
d=symc(c,p);
\$=currentpicture;
draw p--q;
draw c--d;
draw (c--d) shifted (q-p);
\$
endgroup
enddef;
vardef codeperp(expr a,b,c) =
(b+5*unitvector(a-b))--(b+5*unitvector(a-b)+5*unitvector(c-b))--(b+5*unitvector(c-b))
enddef;
vardef per(expr p,q,r,n)=
save \$,cc,ce,cd,cf;
path \$;
pair cc,ce;
path cd,cf;
cc=(r-q) rotated 90 shifted q;
ce=cc shifted (p-q);
\$=droite(ce,p,n);
\$
enddef;
vardef perp(expr p,q,r,n)=%point-droite-longueur de la perpendiculaire.
save \$,cc,ce,cd,cf;
picture \$;
pair cc,ce;
path cd,cf;
\$=currentpicture;
cc=(r-q) rotated 90 shifted q;
ce=cc shifted (p-q);
cd=droite(ce,p,n);
draw cd;
cf=droite(q,r,10);
draw codeperp(ce,cf intersectionpoint cd,r);
\$
enddef;
def triangl(expr p,q,r)=%3 mesures (+ grande en 1er)
begingroup
save \$,a,b,c,cc,cd,lcc,lcd;
picture \$;
pair a,b,c;
path cc,cd;
numeric lcc,lcd;
\$=currentpicture;
a=(2*unit,2*unit);
b=a shifted (p*unit,0);
cc=cercle(a,q*unit);
cd=cercle(b,r*unit);
c=cc intersectionpoint cd;
draw a--c--b;
draw segment(a,b);
lcc=(angle(c-a))*(length cc)/360;
lcd=(angle(c-b))*(length cd)/360;
draw subpath(0.8*lcc,1.2*lcc) of cc;
draw subpath(0.8*lcd,1.2*lcd) of cd;
\$
endgroup
enddef;
def triangle(expr p,q,r)=%longueur(+grande)-angle-longueur à partir du sommet de l'angle.
begingroup
save \$,a,b,c,d,cc,cd,lcc;
picture \$;
pair a,b,c,d;
path cc,cd;
numeric lcc;
\$=currentpicture;
a=(2*unit,2*unit);
b=a shifted (p*unit,0);
draw segment(a,b);
cc=cercle(a,r*unit);
d=b rotated q shifted a;
cd=demidroite(a,d);
draw cd dashed evenly;
c=cd intersectionpoint cc;
draw a--c--b;
lcc=(angle(c-a))*(length cc)/360;
draw subpath(0.8*lcc,1.2*lcc) of cc;
draw codeang(c,a,b,1);
\$
endgroup
enddef;
def triangles(expr p,q,r)=%longueur-angle-angle
begingroup
save \$,a,b,c,d,e,cc,cd;
picture \$;
pair a,b,c,d,e;
path cc,cd;
\$=currentpicture;
a=(2*unit,2*unit);
b=a shifted (p*unit,0);
draw segment(a,b);
d=b rotated q shifted a;
e=a rotated (180-angle(a)-r) shifted b;
cc=demidroite(a,d);
cd=demidroite(b,e);
draw cc dashed evenly;
draw cd dashed evenly;
c=cd intersectionpoint cc;
draw codeang(c,b,a,1);
draw a--c--b;
draw codeang(c,a,b,1.5);
draw codeang(c,a,b,2);
\$
endgroup
enddef;
def rapporteur(expr p,q)=%segment sur lequel placer le rapporteur (centre du rapporteur en premier)
begingroup;
save \$,cc,cd,v,w,t,ww,vv;
picture \$;
path cc,cd;
pair a[],b[],v,w,t,ww,vv;
cc=cercle(p,3u);
cd=p--q;
t=cc intersectionpoint cd;
w=t-2*unitvector(q-p);v=symc(w,t);
ww=t-5*unitvector(q-p);vv=symc(ww,t);
for i=0 upto 35 :
for j=1 upto 4 :
a[5*i+j]=(w-p) rotated (-5*i-j) shifted p;
b[5*i+j]=(v-p) rotated (-5*i-j) shifted p;
endfor;
a[5*(i+1)]=(ww-p) rotated (-5*(i+1)) shifted p;
b[5*(i+1)]=(vv-p) rotated (-5*(i+1)) shifted p;
endfor
\$=currentpicture;
draw subpath(((length cc)/2)+(angle(p-q)*(length cc))/360,(angle(p-q)*(length cc))/360) of cc;
for i=0 upto 35 :
for j=1 upto 4 :
draw a[5*i+j]--b[5*i+j];
endfor;
draw a[5*(i+1)]--b[5*(i+1)] withpen pencircle scaled 1.25bp;
endfor
\$
endgroup;
enddef;
def ekerd(expr q,r,s,t,n)=%droite(q,r)-position sur la droite (point)-sens-"hauteur" de l'équerre
begingroup;
save \$,pt,ptt,pttt,eqer,w;
picture \$;
pair ptt,pttt,eqer,w;
\$=currentpicture;
if t=1 :
ptt=n*(r-q) rotated 90 shifted s;
else :
ptt=n*(r-q) rotated (-90) shifted s;
fi;
w=unitvector(r-q);
pttt=s shifted (50*w);
draw s--ptt--pttt--cycle dashed evenly;draw codeperp(ptt,s,pttt) dashed evenly;
\$
endgroup;
enddef;
def ekerf(expr q,r,s,t,n)=%droite(q,r)-position sur la droite (point)-sens-"hauteur" de l'équerre
begingroup;
save \$,pt,ptt,pttt,eqer,w;
picture \$;
pair ptt,pttt,eqer,w;
\$=currentpicture;
if t=1 :
ptt=n*(r-q) rotated 90 shifted s;
else :
ptt=n*(r-q) rotated (-90) shifted s;
fi;
w=unitvector(r-q);
pttt=s shifted (50*w);
draw s--ptt--pttt--cycle;draw codeperp(ptt,s,pttt);
\$
endgroup;
enddef;
def regle(expr q,r,s,t)=%droite(p,q)-position-longueur de regle
begingroup;
save \$,qt,qtt,qts,qtts,w,ww;
picture \$;
pair qt,qtt,qts,qtts,w,ww;
\$=currentpicture;
qt=t[r,q];
qtt=t[q,r];
if s=1:
w=((qtt-qt) rotated 90) shifted qt;
ww=unitvector(w-qt);
qts=qt shifted (30*ww);
qtts=qts shifted (qtt-qt);
else:
w=((qtt-qt) rotated (-90)) shifted qt;
ww=unitvector(w-qt);
qts=qt shifted (30*ww);
qtts=qts shifted (qtt-qt);
fi;
draw qt--qts--qtts--qtt--cycle;
\$
endgroup;
enddef;
vardef hachure(expr angle,n)=%angle d'hachure-espace
save \$;
picture \$;
pair hach[];
path premiere;
hach0=(0,0);hach1=(1cm,0);
hach2=hach1 rotated angle;
premiere=200[hach0,hach2]--200[hach2,hach0];
draw premiere;
for i=1 upto 100 :
draw premiere shifted (n*i*hach1);
draw premiere shifted (n*(-i)*hach1);
endfor
\$=currentpicture;
\$
enddef;
def rectangle(expr p,q,n,m)=%2 pts formant la longueur- largeur - sens de rotation (1 +,-1 -)
begingroup;
save \$,r,s,t;
picture \$;
pair r,s,t;
t=(p-q) rotated (m*90) shifted q;
r=(n/abs(p-q))[q,t];
s=r shifted (p-q);
draw p--q--r--s--cycle;
draw codeperp(p,q,r);
draw codeperp(q,r,s);
draw codeperp(r,s,p);
\$=currentpicture;
\$
endgroup;
enddef;
def carre(expr p,q,n,m)=%2points - sens direct ou indirect-nƒ du codage
begingroup;
save \$,r,s;
picture \$;
pair r,s;
r=(p-q) rotated (n*90) shifted q;
s=r shifted (p-q);
draw p--q--r--s--cycle;
draw codeperp(p,q,r);
draw codeperp(q,r,s);
draw codeperp(r,s,p);
draw codesegments(p,q,q,r,m);
draw codesegments(r,s,s,p,m);
\$=currentpicture;
\$
endgroup;
enddef;
def compas(expr p,q,n)=%Centre-extrémités-sens
begingroup;
picture \$;
pair r,s,t,a,b,c,d,e,f;
if (abs(p-q)<10*u):
r=((q-milieu(p,q)) rotated (n*90)) shifted milieu(p,q);
else:
r=0.25[milieu(p,q),((q-milieu(p,q)) rotated (n*90)) shifted milieu(p,q)];
fi
s=(1+50/abs(p-q))[milieu(p,q),r];
t=10*unitvector(q-p) rotated (n*90);
a=p shifted t;
b=s shifted (5*unitvector(p-q)+10*unitvector(s-r));
c=b shifted (30*unitvector(s-r));
path comp;
comp=a--b--c--d--e--f--s--a--cycle;
fill comp withcolor black;
draw p--a withpen pencircle scaled 1.5bp;
draw f--q withpen pencircle scaled 1.5bp withcolor 0.25[red,blue];
\$=currentpicture;
\$
endgroup;
enddef;
def circulaire(expr centre,rayon,n)=%nombre de valeurs
begingroup;
save \$,cc,camembert,lcc;
picture \$;
numeric cumule[],lcc[];
path camembert[],cc;
cumule0=0;
for vue=1 upto n:
cumule[vue]=cumule[vue-1]+effectif[vue];
endfor
cc=cercle(centre,rayon);
for vue=1 upto n:
camembert[vue]=centre--(point((cumule[vue-1]/cumule[n])*length cc) of cc)--(subpath((cumule[vue-1]/cumule[n])*length cc,(cumule[vue]/cumule[n])*length cc) of cc)--cycle;
fill camembert[vue] withcolor (vue/n)[red,blue];
draw camembert[vue];
endfor
\$=currentpicture;
\$
endgroup;
enddef;
endinput
```