| 1 |
% slingshot.mp |
| 2 |
% L. Nobre G. |
| 3 |
% 2008 |
| 4 |
|
| 5 |
input featpost3Dplus2D; |
| 6 |
|
| 7 |
% bash: export TEX=latex |
| 8 |
% tcsh: setenv TEX latex |
| 9 |
|
| 10 |
%prologues := 0; |
| 11 |
|
| 12 |
% verbatimtex |
| 13 |
% \documentclass{article} |
| 14 |
% \usepackage{beton,concmath,ccfonts} |
| 15 |
% \begin{document} |
| 16 |
% etex |
| 17 |
|
| 18 |
f := (30,0,0); |
| 19 |
Spread := 100; |
| 20 |
MaxFearLimit := 50; |
| 21 |
|
| 22 |
numeric initdist, timestep, Gfactor, vplanet, vprobe; |
| 23 |
numeric targetangle, cutlinangle; |
| 24 |
inidist = 10; |
| 25 |
timestep = 0.1; |
| 26 |
Gfactor = 7; |
| 27 |
vplanet = 1.3; |
| 28 |
vprobe = 1.2; |
| 29 |
numeric numsteps, cutlinelen, distfraction, numtries, diststep, i, ip; |
| 30 |
numeric a, aa, ab, ac; |
| 31 |
color inipos, inivel, dstp, iter; |
| 32 |
path cutlinepath, traject; |
| 33 |
|
| 34 |
def gravitfield( expr relatposprobe ) = |
| 35 |
( -Gfactor*relatposprobe/((conorm( relatposprobe ))**3) ) |
| 36 |
enddef; |
| 37 |
|
| 38 |
def costfu( expr actang ) = |
| 39 |
(((cutlinangle-actang-targetangle)/targetangle)**2) |
| 40 |
enddef; |
| 41 |
|
| 42 |
vardef scalarfu( expr index ) = |
| 43 |
traject:=trajectorypath( |
| 44 |
numsteps, |
| 45 |
inipos+index*dstp, |
| 46 |
inivel, |
| 47 |
timestep)(gravitfield); |
| 48 |
draw traject; |
| 49 |
ip := xpart( traject intersectiontimes cutlinepath ); |
| 50 |
a := costfu( angle(direction ip of traject) ); |
| 51 |
( a ) |
| 52 |
enddef; |
| 53 |
|
| 54 |
beginfig(1); |
| 55 |
targetangle = 50; |
| 56 |
cutlinelen = 15; |
| 57 |
distfraction = 0.74; |
| 58 |
numtries = 36; |
| 59 |
numsteps = 135; |
| 60 |
diststep = distfraction*inidist/numtries; |
| 61 |
dstp = (0,0,diststep); |
| 62 |
inipos = (0,0,-inidist); |
| 63 |
inivel = (0,-vplanet,vprobe); |
| 64 |
cutlinangle = angle( (-vplanet,vprobe) ); |
| 65 |
%cartaxes( 1, 1, 1 ); |
| 66 |
cutlinepath = rp(black)--rp(cutlinelen*N(inivel)); |
| 67 |
draw cutlinepath withcolor red; |
| 68 |
drawoptions( withcolor blue ); |
| 69 |
for i=0 upto numtries: |
| 70 |
show (i,scalarfu( i )); |
| 71 |
endfor; |
| 72 |
drawoptions(); |
| 73 |
iter = (0,0.5*numtries,numtries); |
| 74 |
message "--------------------------------------------------------"; |
| 75 |
forever: |
| 76 |
iter := minimizestep( iter )( scalarfu ); |
| 77 |
exitif (Z(iter)-X(iter)<0.5) or (Y(iter)<0.005); |
| 78 |
endfor; |
| 79 |
draw traject withcolor green withpen (pencircle scaled (2.5mm)) ; |
| 80 |
produce_auto_scale; |
| 81 |
endfig; |
| 82 |
|
| 83 |
% verbatimtex |
| 84 |
% \end{document} |
| 85 |
% etex |
| 86 |
|
| 87 |
end. |