versiera.mp [ source brut ]
input geometrie2d; input courbes; picture pict; O = Point(0,0); pict = image( Repere(20,7,10,1,5,5); remplis fullcircle shifted (0,0.5) withcolor (0.5,0.7,0.7); trace fullcircle shifted (0,0.5) withcolor (0.3,0.5,0.5); Axes; Debut; trace Droite((-3,1),(3,1)); marque.llft "O"; Fin; ); vardef f(expr t) = 1 / ( 1 + t*t) enddef; n = 95; for i=0 upto n: beginfig(i+1); draw pict; Repere(12,4,6,0.5,3,3); Debut; x := -2+4*i/n; a := angle((x,1)); xb := sind(a)*cosd(a); yb := sind(a)*sind(a); trace Droite((0,0),(x,1)) withcolor 0.6white; trace Droite((x,0),(x,1)) withcolor 0.6white; trace Droite((-2,yb),(2,yb)) withcolor 0.6white; trace Representation(f,-2,x,floor((x+2)*5+2)) withcolor red; A := Point(x,1); if x < 0: marque.urt "A" else: marque.ulft "A" fi; pointe (xb,yb); pointe (x,yb); pointe O; Fin; endfig; endfor; end
geometrie2d.mp [ source brut ]
input labels; string ogT[]; numeric ogTA[], ogTB[], ogTC[], ogTD[], ogTE[], ogTF[]; numeric ogt, gTRD, gU, gPR; % ogt est le compteur des objets graphiques créés. ogt := 0; % Paramètre utilisé pour le tracé des droites. Il fixe la longueur du segment % tracé en fonction de la longueur du bipoint qui définit la droite. gTRD := 5; % gU est l'unité de base, ici le cm. gU := 1cm; % gENPLACE est la transformation qui place les objets ... en premier. string gENPLACEs; gENPLACEs = "scaled gU"; def gENPLACE = scantokens gENPLACEs enddef; % diamètre des cercles marquant les points gPR := 2; % Point ----------------------------------------------------------------------- vardef Point (expr a,b) = ogT[incr ogt] = "point"; ogTA[ogt] = a; ogTB[ogt] = b; ogt enddef; % Vecteur --------------------------------------------------------------------- vardef Vecteur (expr a,b) = ogT[incr ogt] = "vecteur"; ogTA[ogt] = a; ogTB[ogt] = b; ogt enddef; % Droite ---------------------------------------------------------------------- vardef Droite (expr a,b) = save n; n = incr ogt; ogT[n] = "droite"; ogTA[n] = if pair a: Point(xpart a,ypart a) else: a fi; ogTB[n] = if pair b: Point(xpart b,ypart b) else: b fi; n enddef; % Segment --------------------------------------------------------------------- vardef Segment (expr a,b) = ogT[incr ogt] = "segment"; ogTA[ogt] = a; ogTB[ogt] = b; ogt enddef; % Triangle -------------------------------------------------------------------- vardef Triangle (expr a,b,c) = ogT[incr ogt] = "triangle"; ogTA[ogt] = a; ogTB[ogt] = b; ogTC[ogt] = c; ogt enddef; % Cercle ---------------------------------------------------------------------- vardef Cercle (expr a,b) = save n; n = incr ogt; ogT[n] = "cercle"; ogTB[n] = b; ogTA[n] = if pair a: Point(xpart a,ypart a) else: a fi; n enddef; % Quadrilatère complet -------------------------------------------------------- vardef QComplet (expr a,b,c,d,e) = save p,r; pair p, numeric r; ogT[incr ogt] = "qcomplet"; r = ogt; ogTA[ogt] = a; ogTB[ogt] = b; ogTC[ogt] = c; ogTD[r] = Point_(d [_Point(a), _Point(b)]); ogTE[r] = Point_(e [_Point(b), _Point(c)]); p = whatever [ _Point(a), _Point(c) ]; p = whatever [ _Point(ogTD[r]), _Point(ogTE[r]) ]; ogTF[r] = Point_(p); r enddef; % Isobarycentre d'une liste de points <t> ..................................... vardef IsoBarycentre (text t) = save x,y,n; x := 0; y := 0; n := 0; for p_ = t: x := x + ogTA[p_]; y := y + ogTB[p_]; n := n + 1 ; endfor; if n>0: Point ((1/n)*x,(1/n)*y) fi enddef; % Barycentre des points <a> et <b>, <b> est affecté du poids x, <a> du poids 1-x vardef Barycentre (expr a,b,x) = save p; pair p; p = x [ _Point(a), _Point(b)]; Point_(p) enddef; % Milieu du segement <a> ...................................................... vardef Milieu (expr a) = IsoBarycentre(ogTA[a],ogTB[a]) enddef; % Médiatrice du segment <a> ................................................... vardef Mediatrice (expr a) = save p,q; pair q; p = Milieu(a); q = _Point(p) + (_Vecteur(a) rotated 90); Droite(p,Point_(q)) enddef; % Bissectrice de l'angle de sommet <b> limité par les points <a> et <c> ....... vardef Bissectrice (expr a,b,c) = save p,q,r,t; pair p,q,r,t; q = _Point(b); p = q + unitvector(_Point(a) - q); r = q + unitvector(_Point(c) - q); t - p = whatever * (q - p) rotated 90; t - r = whatever * (q - r) rotated 90; Droite(b,Point_(t)) enddef; % Perpendiculaire à la droite <b> passant par <a> ............................. vardef Perpendiculaire (expr a,b) = Droite(a,Point_(_Point(a) + (_Vecteur(b) rotated 90))) enddef; % Intersection des droites <a> et <b> ......................................... vardef Intersection (expr a,b) = save p; pair p; p = whatever [ _Point(ogTA[a]), _Point(ogTB[a]) ]; p = whatever [ _Point(ogTA[b]), _Point(ogTB[b]) ]; Point_(p) enddef; % Projection du point <a> sur la droite <b> ................................... vardef Projection (expr a,b) = Point_(_Projection(a,b)) enddef; % Orthocentre du triangle <t> ................................................. vardef Orthocentre (expr t) = Intersection( Perpendiculaire(PointDe(t,1),Droite(PointDe(t,2),PointDe(t,3))), Perpendiculaire(PointDe(t,2),Droite(PointDe(t,3),PointDe(t,1))) ) enddef; % Symétrique de <a> par rapport au point ou à la droite <b> ................... vardef Symetrique (expr a,b) = if ogT[b] = "point": Point_(2 [_Point(a), _Point(b)]) else: Point_(_Point(a) reflectedabout (_Point(ogTA[b]),_Point(ogTB[b]))) fi enddef; % Distance entre le point <a> et le point/droite <b> .......................... vardef Distance (expr a,b) = if ogT[b] = "droite": abs(_Point(a) - _Projection(a,b)) else: abs(_Point(a) - _Point(b)) fi enddef; % Cercle circonscrit au triangle <a> .......................................... vardef CercleCirconscrit (expr a) = save p,r; p = Intersection( Mediatrice(Segment(ogTA[a],ogTB[a])), Mediatrice(Segment(ogTB[a],ogTC[a])) ); r = Distance(p,ogTA[a]); Cercle(p,r) enddef; % Centre du cercle <c> ........................................................ vardef Centre(expr a) = ogTA[a] enddef; % Rayon du cercle <c> ......................................................... vardef Rayon(expr a) = ogTB[a] enddef; %% ============================================================================ %% Transformations %% ============================================================================ vardef Rotation(expr a,b,c) = if path a: a rotatedaround (_Point(b),c) else: Point_(_Point(a) rotatedaround (_Point(b),c)) fi enddef; %% ============================================================================ %% objets Point, Vecteur et pairs au sens de METAPOST. %% Passage des uns aux autres ... %% ============================================================================ def _Point(expr a) = (ogTA[a],ogTB[a]) enddef; def Point_(expr p) = Point(xpart p,ypart p) enddef; let ptoPoint = Point_; def _Vecteur(expr a) = (_Point(ogTB[a]) - _Point(ogTA[a])) enddef; vardef _Projection (expr a,b) = save p; pair p; p = _Point(a) + whatever * _Vecteur(b) rotated 90; p = whatever [ _Point(ogTA[b]), _Point(ogTB[b]) ]; p enddef; %% ---------------------------------------------------------------------------- def PointDe(expr a,b) = if b = 1: ogTA[a] elseif b = 2: ogTB[a] elseif b = 3: ogTC[a] elseif b = 4: ogTD[a] elseif b = 5: ogTE[a] elseif b = 6: ogTF[a] fi enddef; def Lieu expr o = if ogT[o] = "triangle": _Point(ogTA[o])--_Point(ogTB[o])--_Point(ogTC[o])--cycle elseif ogT[o] = "droite": (gTRD [ _Point(ogTA[o]), _Point(ogTB[o]) ]) -- (gTRD [ _Point(ogTB[o]), _Point(ogTA[o]) ]) elseif ogT[o] = "segment": _Point(ogTA[o]) -- _Point(ogTB[o]) elseif ogT[o] = "cercle": fullcircle scaled (ogTB[o]*2) shifted _Point(ogTA[o]) elseif ogT[o] = "qcomplet": _Point(ogTA[o]) -- _Point(ogTB[o]) -- _Point(ogTE[o]) -- _Point(ogTD[o]) -- _Point(ogTA[o]) -- _Point(ogTC[o]) -- _Point(ogTE[o]) fi enddef; def _pointe(expr p) = fill (fullcircle scaled gPR) shifted (p gENPLACE) withcolor white; draw (fullcircle scaled gPR) shifted (p gENPLACE) enddef; def trace expr p = if path p: draw p elseif pair p: draw p else: draw (Lieu p) fi gENPLACE enddef; def remplis expr p = if path p: fill p else: fill (Lieu p) fi gENPLACE enddef; def pointe expr p = if pair p: _pointe(p) else: _pointe(_Point(p)) fi enddef; vardef marque.@# expr p = pointe(scantokens p); label.@#(lTEX(p),_Point(scantokens p) gENPLACE); enddef; 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; vardef Etiquette.@#(expr s,t,p) = label.@#(TEX(s) scaled t,p gENPLACE) enddef; %% ---------------------------------------------------------------------------- def Fenetre(expr xg,yg,xd,yd) = gpXG := xg; gpYG := yg; gpXD := xd; gpYD := yd; extra_endfig := "_fenetre;" & extra_endfig; enddef; def _fenetre = clip currentpicture to ((gpXG,gpYG)--(gpXG,gpYD)--(gpXD,gpYD)--(gpXD,gpYG)--cycle) gENPLACE enddef; %% Rotation globale de la figure ---------------------------------------------- vardef RotationDeFigure(expr a) = ; picture temp; temp = currentpicture; currentpicture := nullpicture; draw temp rotated a; gENPLACEs := gENPLACEs & " rotated " & decimal a; enddef; endinput
reperes.mp [ source brut ]
picture rSAVEPICT; def Repere(expr l,h,ox,oy,ux,uy) = def gENPLACE = xscaled ux yscaled uy shifted (ox,oy) scaled gU enddef; rLARGEUR := l; rHAUTEUR := h; rXMIN := - ox / ux; rXMAX := rXMIN + l / ux; rYMIN := - oy / uy; rYMAX := rYMIN + h / uy; rUX := ux; rUY := uy; enddef; def Debut = rSAVEPICT := currentpicture; currentpicture := nullpicture; enddef; def Fin = clip currentpicture to ( (0,0)--(rLARGEUR,0)--(rLARGEUR,rHAUTEUR)--(0,rHAUTEUR)--cycle) scaled gU; addto rSAVEPICT also currentpicture; currentpicture := rSAVEPICT; def gENPLACE = scaled gU enddef; enddef; def Axes = drawarrow ((rXMIN,0)--(rXMAX,0)) gENPLACE; drawarrow ((0,rYMIN)--(0,rYMAX)) gENPLACE; label.lrt(TEX("$x$"),(rXMAX,0) gENPLACE); label.ulft(TEX("$y$"),(0,rYMAX) gENPLACE); enddef; vardef Graduations = save xmin, xmax, ymin, ymax; xmin = floor(rXMIN); xmax = floor(rXMAX) + 1; ymin = floor(rYMIN); ymax = floor(rYMAX) + 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; % % SequenceTirets % ------------------------------------------------------------------------------ vardef SequenceTirets(expr o,p,t,n) text a= save ot; pair ot; ot := o gENPLACE; for i:=1 upto n: % tiret draw ot -- (ot shifted t) a; % avancement ot := (o + i*p) gENPLACE; endfor enddef; vardef Unites(expr t) = if t=1: label.bot(TEX("$+1$"),(1,-(3/gU/rUY)) gENPLACE); label.ulft(TEX("$+1$"),(-(3/gU/rUX),1) gENPLACE); fi enddef; endinput
labels.mp [ source brut ]
lFOURIER := 1; string lSTRING[]; lSTRING[0] = "alpha"; lSTRING[1] = "beta"; lSTRING[2] = "gamma"; lSTRING[3] = "delta"; lSNB = 3; vardef scanchaine_label(expr s) = save d,m,f,c,l,flag,i; string d,m,f,c; d := ""; m := ""; f := ""; l = length(s); flag := 0; for i:=0 upto l: c := substring (i,i+1) of s; if c = "'": f := f & c; flag := 2; elseif c = "_": flag := 1; else: if flag = 0: d := d & c else: m := m & c fi; fi endfor; for i:=0 upto lSNB: if d = lSTRING[i]: d := "\" & d fi endfor; d := d & "_{" & m & "}" & f; d enddef; vardef lTEX primary s = write "" to "mptextmp.mp"; write "%&latex" to "mptextmp.mp"; write "\documentclass{article}" to "mptextmp.mp"; if lFOURIER=1: write "\usepackage{fourier}" to "mptextmp.mp" fi; write "\begin{document}" to "mptextmp.mp"; write "etex" to "mptextmp.mp"; write "btex $"& scanchaine_label(s) &"$ etex" to "mptextmp.mp"; write EOF to "mptextmp.mp"; scantokens "input mptextmp" enddef; vardef TEX primary s = write "" to "mptextmp.mp"; write "%&latex" to "mptextmp.mp"; write "\documentclass{article}" to "mptextmp.mp"; write "\usepackage[frenchb]{babel}" to "mptextmp.mp"; if lFOURIER=1: write "\usepackage{fourier}" to "mptextmp.mp" fi; write "\usepackage{amsmath}" to "mptextmp.mp"; write "\everymath{\displaystyle}" to "mptextmp.mp"; write "\begin{document}" to "mptextmp.mp"; write "etex" to "mptextmp.mp"; write "btex "& s &" etex" to "mptextmp.mp"; write EOF to "mptextmp.mp"; scantokens "input mptextmp" enddef; vardef FICHIER primary s = save _s; string _s; _s = "input " & s; scantokens _s enddef; endinput