Debian Codegraph @

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

raw
1 % fieldlines.mp
2 % L. Nobre G.
3 % 2003
4
5 input featpost3Dplus2D;
6
7 Spread := 30;
8 f := (10,0,0);
9
10 color posa, posb;
11 numeric kfac;
12 posa = -5*green;
13 posb = 5*green;
14 kfac = 2.5;
15
16 def vecfunc( expr posit )=
17 begingroup
18 save modula, modulb, field;
19 color field;
20 numeric modula, modulb;
21 modula = conorm( posit-posa );
22 modulb = conorm( posit-posb );
23 field = ( posit-posa )/(modula**3)+kfac*( posit-posb )/(modulb**3);
24 ( field )
25 endgroup
26 enddef;
27
28 beginfig(1);
29 numeric i, lena, lenb, numa, numb, sa, sb, diffstep, ray;
30 color stp;
31 path oneline;
32 pen grossa, fina;
33 grossa = pencircle scaled 3pt;
34 fina = pencircle scaled 2pt;
35 lena = 105;
36 lenb = 145;
37 numa = 72;
38 numb = 30;
39 diffstep = 1;
40 ray = 0.5;
41 sa = 36;
42 sb = 75;
43 for i=sa step numa until (360+sa):
44 stp := posa+( 0, ray*cosd(i), ray*sind(i) );
45 oneline := fieldlinepath( lena, stp, diffstep, vecfunc );
46 draw oneline withpen grossa;
47 % draw oneline withpen fina withcolor background;
48 endfor;
49 for i=sb step numb until (360+sb):
50 stp := posb+( 0, ray*cosd(i), ray*sind(i) );
51 oneline := fieldlinepath( lenb, stp, diffstep, vecfunc );
52 draw oneline withpen grossa;
53 % draw oneline withpen fina withcolor background;
54 endfor;
55 draw rp(posa) withpen grossa;
56 draw rp(posb) withpen grossa;
57 endfig;
58
59 end.