summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/featpost/example/fieldlinesnormapaperwork.mp
blob: a2451a4607c17099c32bbf0c6611371e1bbdba2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
% fieldlinesnormapaperwork.mp
% L. Nobre G.
% 2009

input featpost3Dplus2D;

prologues := 1;

Spread := 25;
f := (20,0,0);

color posa, posb, perpd;
numeric limy, limz, bord;
posa = (0,-4,0);  %%%%%%%% allways make Y(posa) < Y(posb) %%%%%%%%%%%
posb = (0,4,0);  %%%%%%%%%%%% never make Y(posa) = Y(posb) %%%%%%%%%
perpd = (1,0,0);
limy = 7;
limz = 5;
bord = 2.5;

def vecfunc( expr posit )=
  begingroup
    save field;
    color field, horiz, verti, vech, vecv;
    numeric modula, modulb, ypos, zpos, hd, hf, vd, vf, zref, yref;
    modula = conorm( posit-posa );
    modulb = conorm( posit-posb );
    field = N( ( posit-posa )/(modula**3)-( posit-posb )/(modulb**3) );
    ypos = Y( posit );
    zpos = Z( posit );
    if Z(posa) <> Z(posb):
      (ypos,zref) = whatever[(Y(posa),Z(posa)),(Y(posb),Z(posb))];
      (yref,zpos) = whatever[(Y(posa),Z(posa)),(Y(posb),Z(posb))];
      if ( abs(zpos) > limz-bord ):
	hd = abs(zpos)-limz+bord;
	if ypos < yref:
	  if zpos > 0:
	    vech = -green;
	  else:
	    vech = green;
	  fi;
	else:
	  if zpos > 0:
	    vech = green;
	  else:
	    vech = -green;
	  fi;
	fi;
      else:
	hd = 0;
	vech = black;
      fi;
    else:
      zref = Z(posa);
      vech = green;
      if ( abs(zpos) > limz-bord ):
	hd = abs(zpos)-limz+bord;
      else:
	hd = 0;
      fi;
    fi;
    if ( abs(ypos) > limy-bord ):
      vd = abs(ypos)-limy+bord;
      if zpos > zref:
	if ypos < 0:
	  vecv = blue;
	else:
	  vecv = -blue;
	fi;
      else:
	if ypos < 0:
	  vecv = -blue;
	else:
	  vecv = blue;
	fi;
      fi;
    else:
      vd = 0;
      vecv = black;
    fi;
    hf = (hd/bord)**2;
    vf = (vd/bord)**2;
    ( N(field*(0.975-hf)*(0.975-vf)+hf*vech+vf*vecv) )
  endgroup
enddef;

def potfunc( expr posit )=
  begingroup
    color field;
    field = vecfunc( posit );
    ( ncrossprod( field, perpd ) )
  endgroup
enddef;
  
beginfig(1);
  numeric i, lena, numa, diffstep, ray;
  color stp;
  path bordeline;
  pen grossa, fina;
  pair auxp;
  grossa = pencircle scaled 3pt; 
  fina = pencircle scaled 1pt; 
  lena = 80;
  numa = 13;
  diffstep = 0.2;
  ray = 0.05;
  drawoptions(withpen grossa);
  for i=1 upto numa-1:
    auxp := (i/numa)[rp(posa),rp(posb)];
    draw auxp;
  endfor;
  drawoptions(withpen fina);
  for i=2 step 2 until numa-2:
    stp := (i/numa)[posa,posb];
    draw fieldlinepath( lena, stp, diffstep, potfunc );
    draw fieldlinepath( lena, stp, -diffstep, potfunc );
  endfor;
%  draw fieldlinepath( lena, (0,Y(posa),Z(posa)+ray), diffstep, vecfunc );
  bordeline = rp((0,-limy,-limz))--rp((0, limy,-limz))--
  rp((0, limy, limz))--rp((0,-limy, limz))--cycle;
  clip currentpicture to bordeline;
  draw bordeline;
  drawoptions(withpen fina);
  numeric side;
  path aux, electri;
  side = 10mm;
  aux = origin--(side,0)--(side,side)--cycle;
  z0 = 0.667[origin,(side,0.5*side)];
  electri = aux shifted (-z0) rotated (45+angle(rp(posb)-rp(posa)));
  draw electri shifted rp(posb);
  draw electri rotated 180 shifted rp(posa);
endfig;

end.