' slingshotmove3 nomainwin UpperLeftX = 10: UpperLeftY = 10 WindowWidth =1000: WindowHeight =700 graphicbox #w.g1, 10, 10, 970, 400 graphicbox #w.g2, 170, 460, 740, 200 button #w.b1, "Freeze?", hold, LR, 50, 10 textbox #w.tb1, 90, 435, 50, 20 textbox #w.tb2, 150, 435, 50, 20 textbox #w.tb3, 210, 435, 50, 20 textbox #w.tb4, 270, 435, 50, 20 textbox #w.tb5, 330, 435, 50, 20 textbox #w.tb6, 390, 435, 50, 20 statictext #w.st1, " 2D representation of ( x,y) positions)", 300, 370, 400, 20 statictext #w.st2, " Speed of satellite against time", 350, 470, 350, 20 statictext #w.st3, " x y vx vy ax ay", 110, 410, 380, 20 open "Slingshot- rocket coasts towards a large planet which is approaching at a comparable velocity" for window as #w #w, "trapclose [quit]" #w.g1, "down ; fill white ; backcolor red ; set "; Mx; " "; My; " ; circlefilled 3 ; backcolor blue" #w.g2, "down" #w.st1, "!font courier 12" #w.st2, "!font courier 12" #w.st3, "!font courier 12" m =1 [main] for Mx.dot =-10 to 3 step 1 y = 174 'to just miss! dt = 0.05 'time interval mx = 0 'x pos'n of approaching mass m (satellite) my = y 'y pos'n of mass m Mx = 600 'Initial x-position of planet M (planet) My = 200 'Initial y-position of planet M mx.dot = 10 'x velocity my.dot = 0 'y velocity for t =0 to 1200 step dt v = ( mx.dot^2 +my.dot^2)^0.5 if v >25.5 then vv =25.5 else vv =v #w.g1, "color "; vv *10; " 40 "; 255 -vv *10 #w.g1, "set "; mx; " "; my; " ; circlefilled 1" #w.tb1, using( "####", mx) #w.tb2, using( "####", my) #w.tb3, using( "###.###", mx.dot) #w.tb4, using( "###.###", my.dot) #w.tb5, using( "##.###", mx.dot.dot) #w.tb6, using( "##.###", my.dot.dot) mx =mx +mx.dot *dt 'update x by adding velocity *dt my =my +my.dot *dt Mx =Mx +Mx.dot *dt #w.g1, "color green" #w.g1, "backcolor red ; set "; Mx; " "; My; " ; circlefilled 3 ; backcolor blue" r =( (mx -Mx)^2 +(my -My)^2)^0.5 a = 6000/r^2/m 'using inverse square law mx.dot.dot = a *( Mx -mx) /r 'x component of acceleration my.dot.dot = a *( My -my) /r 'y component mx.dot =mx.dot +mx.dot.dot *dt 'update velocity by adding acc'n *dt my.dot =my.dot +my.dot.dot *dt t =t +dt 'update time #w.g2, "set "; t*4; " "; 200 -v *3 #w.g2, "set "; t*4; " "; 170 scan if ( ( mx >970) or ( r <5) or ( my >400) or ( my <0) or ( mx <0)) and t >185 then exit for next t next Mx.dot #w.g1, "flush" #w.g2, "flush" wait sub hold j$ #w.g1, "flush" #w.g2, "flush" #w, "getbmp drawing 1 1 1000 700" bmpsave "drawing", "trajectories.bmp" beep notice "Move on?"; jf$ end sub [quit] close #w end