Debian Codegraph @

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

raw
1 % fieldlinesnorma.mp
2 % L. Nobre G.
3 % 2003
4
5 input featpost3Dplus2D;
6
7 Spread := 25;
8 f := (10,-2,7);
9
10 color posa, posb, perpd;
11 numeric kfac;
12 posa = -5*green;
13 posb = 5*green;
14 perpd = (1,0,1);
15 kfac = -10;
16
17 def vecfunc( expr posit )=
18 begingroup
19 save modula, modulb, field;
20 color field;
21 numeric modula, modulb;
22 modula = conorm( posit-posa );
23 modulb = conorm( posit-posb );
24 field = ( posit-posa )/(modula**3)+kfac*( posit-posb )/(modulb**3);
25 ( N(field) )
26 endgroup
27 enddef;
28
29 def potfunc( expr posit )=
30 begingroup
31 save field;
32 color field;
33 field = vecfunc( posit );
34 ( ncrossprod( field, perpd ) )
35 endgroup
36 enddef;
37
38 beginfig(1);
39 numeric i, lena, lenb, numa, numb, sa, sb, diffstep, ray;
40 color stp;
41 path oneline;
42 pen grossa, fina;
43 grossa = pencircle scaled 3pt;
44 fina = pencircle scaled 2pt;
45 lena = 85;
46 lenb = 20;
47 numa = 30;
48 numb = 18;
49 diffstep = 0.1;
50 ray = 0.5;
51 sa = 75;
52 sb = 90;
53 for i=sa step numa until (360+sa):
54 stp := posa+( ray*cosd(i), ray*sind(i), 0 );
55 oneline := fieldlinepath( lena, stp, diffstep, vecfunc );
56 draw oneline withpen grossa;
57 % draw oneline withpen fina withcolor background;
58 endfor;
59 for i=sb step numb until (360+sb):
60 stp := posb+( ray*cosd(i), ray*sind(i), 0 );
61 oneline := fieldlinepath( lenb, stp, -diffstep, vecfunc );
62 draw oneline withpen grossa;
63 % draw oneline withpen fina withcolor background;
64 endfor;
65 draw rp(posa) withpen grossa;
66 draw rp(posb) withpen grossa;
67 endfig;
68
69 Spread := 17;
70 f:= (10,-6,7);
71
72 beginfig(2);
73 numeric i, lena, lenb, numa, numb, sa, sb, diffstep, ang;
74 color stp;
75 path oneline;
76 pen grossa, fina;
77 grossa = pencircle scaled 3pt;
78 fina = pencircle scaled 2pt;
79 lena = 85;
80 lenb = 125;
81 numa = 0.03;
82 numb = 0.30;
83 diffstep = 0.2;
84 ang = -90;
85 sa = 1.5;
86 sb = 4.5;
87 for i=sa step numa until (1.5+sa):
88 stp := posa+i*cosd(ang)*green+i*sind(ang)*ncrossprod(perpd,green);
89 oneline := fieldlinepath( lena, stp, diffstep, potfunc );
90 draw oneline withpen grossa;
91 % draw oneline withpen fina withcolor background;
92 endfor;
93 ang := 180;
94 for i=sb step numb until (3.7+sb):
95 stp := posb+i*cosd(ang)*green+i*sind(ang)*ncrossprod(perpd,green);
96 oneline := fieldlinepath( lenb, stp, diffstep, potfunc );
97 draw oneline withpen grossa;
98 % draw oneline withpen fina withcolor background;
99 endfor;
100 draw rp(posa) withpen grossa;
101 draw rp(posb) withpen grossa;
102 endfig;
103
104 end.