Debian Codegraph @

texmf-dist/metapost/mp-geom2d/geom2d-plt.mp

raw
1 %
2 % Courbe param�tr�e
3 % ------------------------------------------------------------------------------
4 vardef Courbe(suffix fx)(suffix fy)(expr ti,tf,n) =
5 save fpas; fpas := (tf-ti)/n;
6 (fx(ti),fy(ti)) for i=1 upto n: ..(fx(ti+i*fpas),fy(ti+i*fpas)) endfor
7 enddef;
8
9 vardef Curve(suffix fx)(suffix fy)(expr ti,tf,n) = Courbe(fx)(fy)(ti,tf,n) enddef;
10
11 %
12 % Repr�sentation de fonction
13 % ------------------------------------------------------------------------------
14 vardef Representation(suffix f)(expr ti,tf,n) =
15 save fpas;
16 fpas := (tf-ti)/n;
17 (ti,f(ti)) for i=1 upto n: ..(ti+i*fpas,f(ti+i*fpas)) endfor
18 enddef;
19
20 vardef Plot(suffix f)(expr ti,tf,n) = Representation(f)(ti,tf,n) enddef;
21
22 %
23 % Courbe en polaire
24 % ------------------------------------------------------------------------------
25 vardef CourbeEnPolaires(suffix r)(expr ti,tf,n) =
26 save fpas,t;
27 fpas := (tf-ti)/n;
28 r(ti)*(cos(ti),sin(ti))
29 for i=1 upto n: hide(t:=ti+i*fpas) .. r(t)*(cos(t),sin(t)) endfor
30 enddef;
31
32 vardef PolarCurve(suffix r)(expr ti,tf,n) = CourbeEnPolaires(r)(ti,tf,n) enddef;
33
34 %
35 % Champs de vecteurs
36 % ------------------------------------------------------------------------------
37 vardef ChampVecteurs(suffix f)(expr x,y,px,py,dx,couleur) =
38 for i = 0 upto (x - repXmin)/px:
39 for j = 0 upto (y - repYmin)/py:
40 drawarrow
41 (((0,0)--dx*unitvector((1,f(x-i*px,y-j*py))))
42 shifted (x-i*px,y-j*py)) gddEnPlace
43 withcolor couleur;
44 endfor
45 for j = 0 upto (repYmax - y)/py:
46 drawarrow
47 (((0,0)--dx*unitvector((1,f(x-i*px,y+j*py))))
48 shifted (x-i*px,y+j*py)) gddEnPlace
49 withcolor couleur;
50 endfor
51 endfor
52 for i = 0 upto (repXmax - x)/px:
53 for j = 0 upto (y - repYmin)/py:
54 drawarrow
55 (((0,0)--dx*unitvector((1,f(x+i*px,y-j*py))))
56 shifted (x+i*px,y-j*px)) gddEnPlace
57 withcolor couleur;
58 endfor
59 for j = 0 upto (repYmax - y)/py:
60 drawarrow
61 (((0,0)--dx*unitvector((1,f(x+i*px,y+j*py))))
62 shifted (x+i*px,y+j*py)) gddEnPlace
63 withcolor couleur;
64 endfor
65 endfor
66 enddef;
67
68 vardef VectorField(suffix f)(expr x,y,px,py,dx,couleur) =
69 ChampVecteurs(f)(x,y,px,py,dx,couleur) enddef;
70
71 %
72 % Champs de vecteurs f R^2 -> R^2
73 % ------------------------------------------------------------------------------
74 vardef ChampVecteursDD(suffix f)(expr x,y,px,py,dx,couleur) =
75 for i = 0 upto (x - repXmin)/px:
76 for j = 0 upto (y - repYmin)/py:
77 drawarrow
78 (((0,0)--dx*unitvector(f(x-i*px,y-j*py)))
79 shifted (x-i*px,y-j*py)) gddEnPlace
80 withcolor couleur;
81 endfor
82 for j = 0 upto (repYmax - y)/py:
83 drawarrow
84 (((0,0)--dx*unitvector(f(x-i*px,y+j*py)))
85 shifted (x-i*px,y+j*py)) gddEnPlace
86 withcolor couleur;
87 endfor
88 endfor
89 for i = 0 upto (repXmax - x)/px:
90 for j = 0 upto (y - repYmin)/py:
91 drawarrow
92 (((0,0)--dx*unitvector(f(x+i*px,y-j*py)))
93 shifted (x+i*px,y-j*px)) gddEnPlace
94 withcolor couleur;
95 endfor
96 for j = 0 upto (repYmax - y)/py:
97 drawarrow
98 (((0,0)--dx*unitvector(f(x+i*px,y+j*py)))
99 shifted (x+i*px,y+j*py)) gddEnPlace
100 withcolor couleur;
101 endfor
102 endfor
103 enddef;
104
105 vardef VectorFieldDD(suffix f)(expr x,y,px,py,dx,couleur) =
106 ChampVecteursDD(f)(x,y,px,py,dx,couleur) enddef;
107
108 endinput;