| 1 |
% metalcharge.mp |
| 2 |
% L. Nobre G. |
| 3 |
% IYP (2005) |
| 4 |
|
| 5 |
input featpost3Dplus2D; |
| 6 |
|
| 7 |
def parabolline( expr ParC, FracofLen ) = |
| 8 |
begingroup |
| 9 |
numeric Xlengh, Xcontx, Xconty, Xpos, Xa, Xb, Xyfin; |
| 10 |
Xlengh = X( ParC ); |
| 11 |
Xcontx = Y( ParC ); |
| 12 |
Xconty = Z( ParC ); |
| 13 |
Xpos = Xlengh*FracofLen; |
| 14 |
if FracofLen < Xcontx/Xlengh : |
| 15 |
Xa = Xconty*(2/Xcontx - 1/(Xcontx-Xlengh)); |
| 16 |
Xb = Xconty*(Xcontx/(Xcontx-Xlengh)-1)/(Xcontx**2); |
| 17 |
Xyfin = Xa*Xpos+Xb*(Xpos**2); |
| 18 |
else: |
| 19 |
Xyfin = Xconty*((Xpos-Xcontx)/(Xcontx-Xlengh)+1); |
| 20 |
fi; |
| 21 |
( Xyfin ) |
| 22 |
endgroup |
| 23 |
enddef; |
| 24 |
|
| 25 |
beginfig(1); |
| 26 |
numeric i, j, k, ang, lengh, contx, conty, resol, pot[], lim, resola, u; |
| 27 |
numeric ringcharg[], rinray[], lstep, coun, sumc, dist, sump, fact, sca; |
| 28 |
color actpoi, scanpoi, dirv; |
| 29 |
pair shiv; |
| 30 |
path form, chargedensity, simetr, revolenvel; |
| 31 |
lengh = 1.6; |
| 32 |
contx = 0.5; |
| 33 |
% contx = 0.9; |
| 34 |
conty = 0.75; |
| 35 |
fact = 0.3; |
| 36 |
lim = 30; |
| 37 |
resol = 30; |
| 38 |
sca = 0.17; |
| 39 |
u = 6cm; |
| 40 |
shiv = (4cm, 12cm); |
| 41 |
resola = 12; %make it even |
| 42 |
viewcentr := (0,contx,0); |
| 43 |
lstep = lengh/resol; |
| 44 |
coun = 0; |
| 45 |
for i = 1 upto resol: |
| 46 |
rinray[i] = parabolline( (lengh, contx, conty), (i-0.5)/resol ); |
| 47 |
ringcharg[i] = 1; |
| 48 |
endfor; |
| 49 |
forever: |
| 50 |
coun := incr( coun ); |
| 51 |
sump := 0; |
| 52 |
for k=1 upto resol: |
| 53 |
actpoi := green*lengh*(k-0.5)/resol + blue*rinray[k]; |
| 54 |
pot[k] := 0; |
| 55 |
for i=1 upto resol: |
| 56 |
for j=1 upto resola: |
| 57 |
ang := 360*(j-0.5)/resola-180; |
| 58 |
scanpoi:=green*lengh*(i-0.5)/resol+rinray[i]*(sind(ang),0,cosd(ang)); |
| 59 |
dirv := actpoi - scanpoi; |
| 60 |
dist := 50*conorm( dirv ); |
| 61 |
pot[k] := pot[k] + ringcharg[i]/dist; |
| 62 |
endfor; |
| 63 |
endfor; |
| 64 |
sump := sump + pot[k]; |
| 65 |
endfor; |
| 66 |
sump := sump/resol; |
| 67 |
sumc := 0; |
| 68 |
for k=1 upto resol: |
| 69 |
ringcharg[k] := ringcharg[k]*(1+fact*(sump-pot[k])/sump); |
| 70 |
sumc := sumc + ringcharg[k]; |
| 71 |
endfor; |
| 72 |
for k=1 upto resol: |
| 73 |
ringcharg[k] := ringcharg[k]*resol/sumc; |
| 74 |
endfor; |
| 75 |
exitif coun>lim; |
| 76 |
show ringcharg[resol]; |
| 77 |
endfor; |
| 78 |
for i=1 upto resol: |
| 79 |
ringcharg[i] := ringcharg[i]/rinray[i]; |
| 80 |
endfor; |
| 81 |
chargedensity = ((lstep*u,sca*ringcharg1*u) |
| 82 |
for i=2 upto resol: |
| 83 |
--(i*lstep*u,sca*ringcharg[i]*u) |
| 84 |
endfor) shifted shiv; |
| 85 |
draw chargedensity; |
| 86 |
form = ((lstep*u,rinray1*u) |
| 87 |
for i=2 upto resol: |
| 88 |
..(i*lstep*u,rinray[i]*u) |
| 89 |
endfor) shifted shiv; |
| 90 |
simetr = ((lstep*u,-rinray1*u) |
| 91 |
for i=2 upto resol: |
| 92 |
..(i*lstep*u,-rinray[i]*u) |
| 93 |
endfor) shifted shiv; |
| 94 |
revolenvel = form...(reverse simetr)...cycle; |
| 95 |
draw revolenvel withcolor red; |
| 96 |
endfig; |
| 97 |
|
| 98 |
end. |