--- /dev/null
+if unknown Pi: input gdd-fct; fi;
+if unknown repSavePict: input gdd-rep; fi;
+
+%
+% Courbe paramétrée
+% ------------------------------------------------------------------------------
+vardef Courbe(suffix fx)(suffix fy)(expr ti,tf,n) =
+ save fpas; fpas := (tf-ti)/n;
+ (fx(ti),fy(ti)) for i=1 upto n: ..(fx(ti+i*fpas),fy(ti+i*fpas)) endfor
+enddef;
+
+%
+% Représentation de fonction
+% ------------------------------------------------------------------------------
+vardef Representation(suffix f)(expr ti,tf,n) =
+ save fpas;
+ fpas := (tf-ti)/n;
+ (ti,f(ti)) for i=1 upto n: ..(ti+i*fpas,f(ti+i*fpas)) endfor
+enddef;
+
+%
+% Courbe en polaire
+% ------------------------------------------------------------------------------
+vardef CourbeEnPolaires(suffix r)(expr ti,tf,n) =
+ save fpas,t;
+ fpas := (tf-ti)/n;
+ r(ti)*(cos(ti),sin(ti))
+ for i=1 upto n: hide(t:=ti+i*fpas) .. r(t)*(cos(t),sin(t)) endfor
+enddef;
+
+%
+% Champs de vecteurs
+% ------------------------------------------------------------------------------
+vardef ChampVecteurs(suffix f)(expr x,y,px,py,dx,couleur) =
+ for i = 0 upto (x - repXmin)/px:
+ for j = 0 upto (y - repYmin)/py:
+ drawarrow
+ (((0,0)--dx*unitvector((1,f(x-i*px,y-j*py))))
+ shifted (x-i*px,y-j*py)) gddEnPlace
+ withcolor couleur;
+ endfor
+ for j = 0 upto (repYmax - y)/py:
+ drawarrow
+ (((0,0)--dx*unitvector((1,f(x-i*px,y+j*py))))
+ shifted (x-i*px,y+j*py)) gddEnPlace
+ withcolor couleur;
+ endfor
+ endfor
+ for i = 0 upto (repXmax - x)/px:
+ for j = 0 upto (y - repYmin)/py:
+ drawarrow
+ (((0,0)--dx*unitvector((1,f(x+i*px,y-j*py))))
+ shifted (x+i*px,y-j*px)) gddEnPlace
+ withcolor couleur;
+ endfor
+ for j = 0 upto (repYmax - y)/py:
+ drawarrow
+ (((0,0)--dx*unitvector((1,f(x+i*px,y+j*py))))
+ shifted (x+i*px,y+j*py)) gddEnPlace
+ withcolor couleur;
+ endfor
+ endfor
+enddef;
+
+endinput;
\ No newline at end of file
--- /dev/null
+picture repSavePict;
+string repSaveW;
+
+def Repere(expr l,h,ox,oy,ux,uy) =
+ repLargeur := l; repHauteur := h;
+ repOX := ox ; repOY := oy;
+ repXmin := - ox / ux; repXmax := repXmin + l / ux;
+ repYmin := - oy / uy; repYmax := repYmin + h / uy;
+ repUX := ux; repUY := uy;
+ repSaveW := gddW;
+ gddW := "xscaled repUX yscaled repUY shifted (repOX,repOY) scaled gddU";
+enddef;
+
+def Debut =
+ repSavePict := currentpicture; currentpicture := nullpicture;
+enddef;
+
+def repClip =
+ clip currentpicture to
+ ((0,0)--(repLargeur,0)--(repLargeur,repHauteur)--(0,repHauteur)--cycle)
+ scaled gddU;
+enddef;
+
+def repStroke (expr c) =
+ draw ((0,0)--(repLargeur,0)--(repLargeur,repHauteur)--(0,repHauteur)--cycle)
+ scaled gddU withcolor c;
+enddef;
+
+def Fin =
+ repClip; addto repSavePict also currentpicture; currentpicture := repSavePict;
+ gddW := repSaveW;
+enddef;
+
+def Axes =
+ drawarrow ((repXmin,0)--(repXmax,0)) gddEnPlace;
+ drawarrow ((0,repYmin)--(0,repYmax)) gddEnPlace;
+ label.lrt(TEX("$x$"),(repXmax,0) gddEnPlace);
+ label.ulft(TEX("$y$"),(0,repYmax) gddEnPlace);
+enddef;
+
+vardef Graduations =
+ save xmin, xmax, ymin, ymax;
+ xmin = floor(repXmin); xmax = floor(repXmax) + 1;
+ ymin = floor(repYmin); ymax = floor(repYmax) + 1;
+ SequenceTirets((xmin,0),(1,0),(0,-4),xmax-xmin+1);
+ SequenceTirets((xmin+0.5,0),(1,0),(0,-2),xmax-xmin);
+ SequenceTirets((0,ymin),(0,1),(-4,0),ymax-ymin+1);
+ SequenceTirets((0,ymin+0.5),(0,1),(-2,0),ymax-ymin);
+enddef;
+
+def ClipRepere =
+ extra_endfig := extra_endfig & "repClip;";
+enddef;
+
+%
+% SequenceTirets
+% ------------------------------------------------------------------------------
+vardef SequenceTirets(expr o,p,t,n) text a=
+ save ot; pair ot; ot := o gddEnPlace;
+ for i:=1 upto n:
+ % tiret
+ draw ot -- (ot shifted t) a;
+ % avancement
+ ot := (o + i*p) gddEnPlace;
+ endfor
+enddef;
+
+vardef Unites(expr t) =
+ if t=1:
+ label.bot(TEX("$+1$"),(1,-(3/gddU/repUY)) gddEnPlace);
+ label.ulft(TEX("$+1$"),(-(3/gddU/repUX),1) gddEnPlace);
+ fi
+enddef;
+
+%%% ----------------------------------------------------------------------------
+%%% Grille
+%%% ----------------------------------------------------------------------------
+
+def GrilleRepere =
+ save xmin, xmax, ymin, ymax;
+ xmin = floor(repXmin); xmax = floor(repXmax) + 1;
+ ymin = floor(repYmin); ymax = floor(repYmax) + 1;
+ for i:=xmin upto xmax:
+ draw ((i,ymin)--(i,ymax)) gddEnPlace;
+ endfor;
+ for i:=ymin upto ymax:
+ draw ((xmin,i)--(xmax,i)) gddEnPlace;
+ endfor;
+enddef;
+
+%%% ----------------------------------------------------------------------------
+%%% CadreRepere
+%%% ----------------------------------------------------------------------------
+def CadreRepere =
+ (repXmin,repYmin)--(repXmin,repYmax)--(repXmax,repYmax)--(repXmax,repYmin)--cycle
+enddef;
+
+endinput
\ No newline at end of file
--- /dev/null
+input graph;
+
+%%% ----------------------------------------------------------------------------
+%%% Déclarations
+%%% ----------------------------------------------------------------------------
+
+numeric gddA[];
+numeric gddB[];
+numeric gddC[];
+numeric gddD[];
+numeric gddE[];
+numeric gddF[];
+picture gddL[]; % Table des labels TeX (btex .. etex)
+numeric gddO; % Compteur des objets
+path gddP[]; % Table des chemins (paths internes)
+string gddS[]; % Table des chaînes (noms de fichiers)
+string gddT[]; % Table des types
+numeric gddU; % Unité graphique
+string gddW; % Chaîne spécifiant le placement des objets
+
+%%% ----------------------------------------------------------------------------
+%%% Initialisations
+%%% ----------------------------------------------------------------------------
+
+% Initialisation de gddO -------------------------------------------------------
+gddO := 0;
+
+% Valeur par défaut de gddU ----------------------------------------------------
+gddU := 1cm;
+
+% Initialisation de gddW et procédure associée ---------------------------------
+gddW = "scaled gddU";
+def gddEnPlace = scantokens gddW enddef;
+
+%%% ----------------------------------------------------------------------------
+%%% Définition des objets
+%%% ----------------------------------------------------------------------------
+
+% Point ------------------------------------------------------------------------
+vardef Point(expr a,b) =
+ gddT[incr gddO] = "point";
+ gddA[gddO] = a; gddB[gddO] = b; gddO
+enddef;
+
+vardef PointDansRepere(expr x,y,o,i,j) =
+ gddT[incr gddO] = "point";
+ gddA[gddO] = gddA[o] + x*(gddA[i]-gddA[o]) + y*(gddA[j]-gddA[o]);
+ gddB[gddO] = gddB[o] + x*(gddB[i]-gddB[o]) + y*(gddB[j]-gddB[o]);
+ gddO
+enddef;
+
+vardef CoordonneesRepere(expr m,o,i,j) =
+ save x,y; numeric x,y;
+ gddA[m] = (gddA[i]-gddA[o])*x + (gddA[j]-gddA[o])*y + gddA[o];
+ gddB[m] = (gddB[i]-gddB[o])*x + (gddB[j]-gddB[o])*y + gddB[o];
+ (x,y)
+enddef;
+
+vardef Milieu(expr a,b) =
+ gddT[incr gddO] = "point";
+ gddA[gddO] = 0.5*(gddA[a]+gddA[b]);
+ gddB[gddO] = 0.5*(gddB[a]+gddB[b]);
+ gddO
+enddef;
+
+% Transformations pair <-> Point -----------------------------------------------
+def PointTOPair(expr a) = (gddA[a],gddB[a]) enddef;
+def PairTOPoint(expr p) = Point(xpart p,ypart p) enddef;
+def PairImp(expr a) = if pair a: a else: PointTOPair(a) fi enddef;
+def PointImp(expr a) = if pair a: PairTOPoint(a) else: a fi enddef;
+def Pt(expr a) = (gddA[a],gddB[a]) enddef;
+def PtR(expr a) = (gddA[a],gddB[a]) gddEnPlace enddef;
+
+
+% Addition ---------------------------------------------------------------------
+vardef AdditionAbscisses(expr a,b) = if pair a: xpart a else: gddA[a] fi + if pair b: xpart b else: gddA[b] fi enddef;
+vardef AdditionOrdonnees(expr a,b) = if pair a: ypart a else: gddB[a] fi + if pair b: ypart b else: gddB[b] fi enddef;
+vardef Addition(expr a,b) =
+ gddT[incr gddO] = "paire";
+ gddA[gddO] = AdditionAbscisses(a,b);
+ gddB[gddO] = AdditionOrdonnees(a,b);
+ gddO
+enddef;
+
+% Vecteur ----------------------------------------------------------------------
+vardef Vecteur (expr a,b) =
+ save n; n = incr gddO;
+ gddT[n] = "vecteur"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
+enddef;
+
+
+% Segment ----------------------------------------------------------------------
+vardef Segment (expr a,b) =
+ save n; n = incr gddO;
+ gddT[n] = "segment"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
+enddef;
+
+% Triangle ---------------------------------------------------------------------
+vardef Triangle (expr a,b,c) =
+ save n; n = incr gddO; gddT[n] = "triangle";
+ gddA[n] = PointImp(a); gddB[n] = PointImp(b); gddC[n] = PointImp(c); n
+enddef;
+
+% Droite -----------------------------------------------------------------------
+vardef Droite (expr a,b) =
+ save n; n = incr gddO;
+ gddT[n] = "droite"; gddA[n] = PointImp(a); gddB[n] = PointImp(b); n
+enddef;
+
+% Équation de droite : triplet (u,v,w) tel que ux+vy+w=0 -----------------------
+% L'équation rendue est normalisée !
+vardef EquationDroite(expr d) =
+ save u, v, w, n;
+ u := gddB[gddB[d]] - gddB[gddA[d]];
+ v := gddA[gddA[d]] - gddA[gddB[d]];
+ w := - u * gddA[gddA[d]] - v * gddB[gddA[d]];
+ n := u ++ v;
+ (u/n,v/n,w/n)
+enddef;
+
+% Ordonnée relative à une droite orientée --------------------------------------
+vardef OrdonneeRelativePointDroite(expr p, d) =
+ savec u, v, w;
+ (u,v,w) = EquationDroite(d);
+ u * gddA[p] + v * gddB[p] + w
+enddef;
+
+% Distance d'un point à une droite ---------------------------------------------
+def DistancePointDroite(expr p, d) =
+ abs(OrdonneeRelativePointDroite(p, d))
+enddef;
+
+% Projection d'un point sur une droite -----------------------------------------
+vardef ProjectionPointSurDroite(expr p, d) =
+ save u,v,w, l;
+ (u,v,w) = EquationDroite(d);
+ l := - u * gddA[p] - v * gddB[p] - w;
+ Point(gddA[p] + l * u, gddB[p] + l * v)
+enddef;
+
+% Cercles ----------------------------------------------------------------------
+vardef Cercle (expr a,b) =
+ save n; n = incr gddO;
+ gddT[n] = "cercle"; gddA[n] = PointImp(a); gddB[n] = b; n
+enddef;
+
+vardef CercleCP(expr a,b) = Cercle(a,abs(Pt(a)-Pt(b))) enddef;
+vardef CercleD(expr a,b) = CercleCP(Milieu(a,b),a) enddef;
+
+% Tangente commune extérieure à deux cercles -----------------------------------
+vardef TangenteCommuneExterieure(expr a, b) =
+ save O, A, d, f; pair O, A;
+ O = (gddB[a]/(gddB[a]-gddB[b]))[Pt(gddA[a]),Pt(gddA[b])]; % Centre de l'homothétie
+ d = abs(O-Pt(gddA[a]));
+ f := if gddA[a] < gddA[b] : 1 else: -1 fi;
+ A = Pt(gddA[a]) rotatedaround(O,angle(d+-+gddB[a],f*gddB[a]));
+ Droite(O,A)
+enddef;
+
+% Intersection de deux cercles -------------------------------------------------
+vardef IntersectionCercles(expr a, b) =
+ save d, x, y, u; pair u;
+ u = unitvector(Pt(gddA[b])-Pt(gddA[a]));
+ d = abs(Pt(gddA[a])-Pt(gddA[b]));
+ x = (gddB[a]**2-gddB[b]**2+d**2)/(2d);
+ y = gddB[a]+-+x;
+ PairTOPoint(Pt(gddA[a])+x*u+y*(u rotated 90))
+enddef;
+
+
+% Chemin -----------------------------------------------------------------------
+vardef Chemin (expr p) =
+ gddT[incr gddO] = "chemin"; gddP[gddO] = p; gddO
+enddef;
+
+% Courbe -----------------------------------------------------------------------
+vardef Courbe (expr s) =
+ gddT[incr gddO] = "courbe"; gddS[gddO] = s; gddO
+enddef;
+
+%%% ----------------------------------------------------------------------------
+%%% Définitions liées au repère
+%%% ----------------------------------------------------------------------------
+
+% Définition de l'origine ------------------------------------------------------
+origine = Point(0,0);
+
+% Définition des axes ----------------------------------------------------------
+AxeOx = Droite(origin,right);
+AxeOy = Droite(origin,up);
+
+%%% ----------------------------------------------------------------------------
+%%% Calculs MetaPost
+%%% ----------------------------------------------------------------------------
+
+vardef mpIntersectionDroites (expr a,b,c,d) =
+ save t; pair t; t = whatever [a,b]; t = whatever [c,d]; t
+enddef;
+
+%%% --------------------------------------------------------------------------
+%%% Tracés des courbes
+%%% --------------------------------------------------------------------------
+vardef gddTraceCourbe (expr f) =
+ save s; gdata(f, s, if i>1:..fi (scantokens s1,scantokens s2))
+enddef;
+
+%%% ----------------------------------------------------------------------------
+%%% Tracés des objets
+%%% ----------------------------------------------------------------------------
+
+gddExtensionDroite := 10;
+
+def gddTraceObjet expr o =
+ if gddT[o] = "triangle":
+ PointTOPair(gddA[o])--PointTOPair(gddB[o])--
+ PointTOPair(gddC[o])--cycle
+ elseif (gddT[o] = "segment") or (gddT[o] = "vecteur"):
+ PointTOPair(gddA[o])--PointTOPair(gddB[o])
+ elseif gddT[o] = "droite":
+ (gddExtensionDroite [ PointTOPair(gddA[o]), PointTOPair(gddB[o]) ]) --
+ (gddExtensionDroite [ PointTOPair(gddB[o]), PointTOPair(gddA[o]) ])
+ elseif gddT[o] = "cercle":
+ fullcircle scaled (gddB[o]*2) shifted PointTOPair(gddA[o])
+ elseif gddT[o] = "chemin":
+ gddP[o]
+ elseif gddT[o] = "courbe":
+ gddTraceCourbe (gddS[o] & ".dta")
+ fi
+enddef;
+
+def trace expr p =
+ if path p or picture p or pair p: draw (p)
+ elseif gddT[p] = "vecteur": drawarrow (gddTraceObjet p)
+ else: draw (gddTraceObjet p)
+ fi gddEnPlace
+enddef;
+
+def fleche expr p =
+ if path p or picture p: drawarrow (p)
+ elseif gddT[p] = "vecteur": drawarrow (gddTraceObjet p)
+ else: drawarrow (gddTraceObjet p)
+ fi gddEnPlace
+enddef;
+
+def colorie expr p =
+ if path p: fill p else: fill (gddTraceObjet p) fi gddEnPlace
+enddef;
+
+def fermeture expr p =
+ if path p: p else: (gddTraceObjet p) fi -- cycle
+enddef;
+
+
+%%% --------------------------------------------------------------------------
+%%% Marque et label des points
+%%% --------------------------------------------------------------------------
+gddTaillePoint := 3; % Diamètre des cercles marquant un point.
+color gddCouleurPoint; % Couleur de fond de la marque d'un point.
+gddCouleurPoint := white;
+gddTailleLabel := 1.5; % Taille d'un label.
+
+
+def gddPointe(expr p) =
+ fill (fullcircle scaled gddTaillePoint) shifted (p gddEnPlace)
+ withcolor gddCouleurPoint;
+ draw (fullcircle scaled gddTaillePoint) shifted (p gddEnPlace)
+enddef;
+
+def pointe expr p = gddPointe(if pair p: p else: PointTOPair(p) fi) enddef;
+
+vardef m_arque.@# expr p =
+ pointe p;
+ label.@#(gddL[p] scaled gddTailleLabel,PointTOPair(p) gddEnPlace);
+enddef;
+
+vardef m_a_rque.@# expr p =
+ pointe(scantokens p);
+ label.@#(lTEX(p),PointTOPair(scantokens p) gddEnPlace);
+enddef;
+
+vardef marque.@# expr p =
+ if string p: m_a_rque.@# p else: m_arque.@# p fi
+enddef;
+
+%%% --------------------------------------------------------------------------
+%%% Signes
+%%% --------------------------------------------------------------------------
+def SigneOrtho(expr a,b,c,x) =
+ (_point_(b) + x * unitvector(_point_(a)-_point_(b)))
+ -- (_point_(b) + x * unitvector(_point_(a) - _point_(b))
+ + x * unitvector(_point_(c) - _point_(b)))
+ -- (_point_(b) + x * unitvector(_point_(c) - _point_(b)))
+enddef;
+
+picture gdd_marque[];
+gdd_marque1 = image(draw (-7,-7)--(7,7));
+gdd_marque2 = image(draw (-7,-7)--(7,7); draw (-7,7)--(7,-7));
+gdd_marque3 = image(draw (-9,-7)--(5,7); draw (-5,-7)--(9,7);
+ draw (-7,7)--(7,-7));
+gdd_marque4 = image(draw (-9,-7)--(5,7); draw (-5,-7)--(9,7);
+ draw (-9,7)--(5,-7); draw (-5,7)--(9,-7));
+
+def Marque(expr a,b,n) =
+ gdd_marque[n] rotated angle(PairImp(b)-PairImp(a)) scaled (0.5/gddU)
+ shifted 0.5[PairImp(a),PairImp(b)]
+enddef;
+
+%%% --------------------------------------------------------------------------
+%%% Fenêtrage
+%%% --------------------------------------------------------------------------
+
+def Fenetre(expr xg,yg,xd,yd) =
+ gddXG := xg;
+ gddYB := yg;
+ gddXD := xd;
+ gddYH := yd;
+ extra_endfig := "gddFenetre;" & extra_endfig;
+enddef;
+
+def gddFenetre =
+ clip currentpicture to
+ ((gddXG,gddYB)--(gddXG,gddYH)--(gddXD,gddYH)--(gddXD,gddYB)--cycle)
+ gddEnPlace;
+ draw ((gddXG,gddYB)--(gddXG,gddYH)--(gddXD,gddYH)--(gddXD,gddYB)--cycle)
+ gddEnPlace withpen pencircle scaled 1 withcolor white;
+enddef;
+
+endinput
\ No newline at end of file