summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/metapost/featpost/example/electricpotential.mp
blob: 1bf47c2e013607685b4f514b6603d1a150a088bf (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
% electricpotential.mp
% L. Nobre G.
% 2004
% PAY ATTENTION: THESE FIGURES ARE INDEPENDANT. CONDUCTOR SURFACE POTENTIAL
% CHANGES UNDER THE INFLUENCE OF EXTERNAL CHARGES.

input featpost3Dplus2D;

f := 16*(4,1,1);
Spread := 35;
LightSource := 10*(4,-3,4);
ActuC := 2;

numeric potlim, cac, cbc, ccc, cdc;
potlim = 2;
cac = 2;
cbc = -2;
ccc = 4;
cdc = 1.5;
pair cap, cbp, ccp;
cap = (-2,-4);
ccp = (-2,4);
cbp = (2,0);
numeric np, ssize;
np = 56;
ssize = 18;

def zi( expr xc, yc ) =
  0
enddef;

def za( expr xc, yc ) =
  begingroup
    save out;
    numeric dist, out;
    dist = abs( (xc,yc)-cap );
    if abs(dist) < 0.005:
      if cac<0:
	out = -potlim;
      else:
	out = potlim;
      fi;
    else:
      out = cac/dist;
    fi;
    if out > potlim:
      out := potlim;
    elseif out < -potlim:
      out := -potlim;
    fi;
    (out)
  endgroup
enddef;

def zb( expr xc, yc ) =
  begingroup
    save out;
    numeric dist, out;
    dist = abs( (xc,yc)-cbp );
    if abs(dist) < 0.005:
      if cbc<0:
	out = -potlim;
      else:
	out = potlim;
      fi;
    else:
      out = cbc/dist + za( xc, yc );
    fi;
    if out > potlim:
      out := potlim;
    elseif out < -potlim:
      out := -potlim;
    fi;
    (out)
  endgroup
enddef;

def zc( expr xc, yc ) =
  begingroup
    save out;
    numeric dist, out;
    dist = abs( (xc,yc)-ccp );
    if abs(dist) < 0.005:
      if ccc<0:
	out = -potlim;
      else:
	out = potlim;
      fi;
    else:
      out = ccc/dist + zb( xc, yc );
    fi;
    if out > potlim:
      out := potlim;
    elseif out < -potlim:
      out := -potlim;
    fi;
    (out)
  endgroup
enddef;

def zd( expr xc, yc ) =
  begingroup
    save out;
    numeric dist, out, i, tmp;
    pair poi;
    tmp = 0;
    for i=0 upto np:
      poi := (i/np)[cap,ccp];
      dist := abs( (xc,yc)-poi );
      if abs(dist) < 0.005:
	if cdc<0:
	  out := -potlim;
	else:
	  out := potlim;
	fi;
      else:
	out := cdc/dist/np;
      fi;
      tmp := tmp+out;
    endfor;
    tmp := tmp + zc( xc, yc );
    if tmp > potlim:
      tmp := potlim;
    elseif tmp < -potlim:
      tmp := -potlim;
    fi;
    (tmp)
  endgroup
enddef;

beginfig(0); 
  hexagonaltrimesh( false, np, ssize, zi );
endfig;

beginfig(1); 
  hexagonaltrimesh( false, np, ssize, za );
endfig;

beginfig(2); 
  hexagonaltrimesh( false, np, ssize, zb );
endfig;

beginfig(3); 
  hexagonaltrimesh( false, np, ssize, zc );
endfig;

% Going into "MetaPost capacity exceeded!"
%
%beginfig(4); 
%  hexagonaltrimesh( false, np, ssize, zd );
%endfig;

end;