Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/mpfields.mp

raw
1 %input mp-tool;
2
3 def projectyz( expr theta, phi ) =
4 (cosd(theta)*sind(phi),sind(theta))
5 enddef;
6
7 numeric vertn, horin, grids, thex, they, varc, xcomp;
8 numeric ymax, xmax, i, j, size, u, ycomp, theta, phi;
9 numeric power;
10 pair actpos, direct, one, two;
11
12 u := 0.5mm;
13 power := 0.8;
14 vertn := 20;
15 horin := 41;
16 size := 3u;
17 grids := 8u;
18 ymax := 0.5*(vertn-1);
19 xmax := 0.5*(horin-1);
20 varc := 90/ymax;
21
22 beginfig(0); % splay
23 pickup pencircle scaled u;
24 for i=-xmax upto xmax:
25 for j=-ymax upto ymax:
26 actpos:=grids*(i,j);
27 thex:=i*varc;
28 they:=j*varc;
29 theta:=90*(cosd(they)**power);
30 phi:=0;
31 direct:=projectyz(theta,phi);
32 one:=actpos-size*direct;
33 two:=actpos+size*direct;
34 draw one--two;
35 endfor;
36 endfor;
37 endfig;
38
39 beginfig(2); % bend
40 pickup pencircle scaled u;
41 for i=-xmax upto xmax:
42 for j=-ymax upto ymax:
43 actpos:=grids*(i,j);
44 thex:=i*varc;
45 they:=j*varc;
46 theta:=90*((1-cosd(they))**(1/power));
47 phi:=0;
48 direct:=projectyz(theta,phi);
49 one:=actpos-size*direct;
50 two:=actpos+size*direct;
51 draw one--two;
52 endfor;
53 endfor;
54 endfig;
55
56 beginfig(4); % twist
57 pickup pencircle scaled u;
58 for i=-xmax upto xmax:
59 for j=-ymax upto ymax:
60 actpos:=grids*(i,j);
61 thex:=i*varc;
62 they:=j*varc;
63 theta:=0;
64 phi:=90*(cosd(they)**power);
65 direct:=projectyz(theta,phi);
66 one:=actpos-size*direct;
67 two:=actpos+size*direct;
68 draw one--two;
69 endfor;
70 endfor;
71 endfig;
72
73 beginfig(3); % splaytwist in splay
74 pickup pencircle scaled u;
75 for i=-xmax upto xmax:
76 for j=-ymax upto ymax:
77 actpos:=grids*(i,j);
78 thex:=i*varc;
79 they:=j*varc;
80 theta:=90*cosd(they)*cosd(thex);
81 phi:=60*sind(2*they)*sind(thex);
82 direct:=projectyz(theta,phi);
83 one:=actpos-size*direct;
84 two:=actpos+size*direct;
85 draw one--two;
86 endfor;
87 endfor;
88 endfig;
89
90 beginfig(5); % splaytwist in twist
91 pickup pencircle scaled u;
92 for i=-xmax upto xmax:
93 for j=-ymax upto ymax:
94 actpos:=grids*(i,j);
95 thex:=i*varc;
96 they:=j*varc;
97 theta:=30*sind(2*they)*sind(thex);
98 phi:=-90*cosd(they)*cosd(thex);
99 direct:=projectyz(theta,phi);
100 one:=actpos-size*direct;
101 two:=actpos+size*direct;
102 draw one--two;
103 endfor;
104 endfor;
105 endfig;
106
107 beginfig(7); % splaytwist in bend
108 pickup pencircle scaled u;
109 for i=-xmax upto xmax:
110 for j=-ymax upto ymax:
111 actpos:=grids*(i,j);
112 thex:=i*varc;
113 they:=j*varc;
114 theta:=90*cosd(they)*sind(thex);
115 phi:=30*sind(2*they)*cosd(thex);
116 direct:=(cosd(theta)*sind(phi),cosd(theta)*cosd(phi));
117 one:=actpos-size*direct;
118 two:=actpos+size*direct;
119 draw one--two;
120 endfor;
121 endfor;
122 endfig;
123
124 beginfig(1); % splay-bend wall
125 pickup pencircle scaled u;
126 for i=-xmax upto xmax:
127 for j=-ymax upto ymax:
128 actpos:=grids*(i,j);
129 thex:=i*varc;
130 they:=j*varc;
131 theta:=0;
132 phi:=2*angle(1,mexp(thex*9));
133 direct:=(cosd(theta)*sind(phi),cosd(theta)*cosd(phi));
134 one:=actpos-size*direct;
135 two:=actpos+size*direct;
136 draw one--two;
137 endfor;
138 endfor;
139 endfig;
140
141 prologues := 1;
142
143 beginfig(6);
144 pickup pencircle scaled u;
145 numeric rescal;
146 rescal = 0.15;
147 for i=-xmax upto xmax:
148 for j=-ymax upto ymax:
149 actpos:=grids*(i,j);
150 thex:=i*rescal;
151 they:=j*rescal;
152 direct:=unitvector((1,they-thex));
153 one:=actpos-size*direct;
154 two:=actpos+size*direct;
155 draw one--two;
156 endfor;
157 endfor;
158 endfig;
159
160 end;