from __future__ import division
from visual import *
from physutil import *

#Window setup
scene.width =1024
scene.height = 760

#Objects
Earth = sphere(pos=vector(0,0,0), radius=6.4e6, material=materials.BlueMarble)
Satellite = sphere(pos=vector(-42164000,0,0), radius=1e6, materials=materials.chrome, make_trail=True)

parrow = arrow(color=color.green)
pscale = 0.5

#Parameters and Initial Conditions
G = 6.7e-11
mEarth = 6e24
mSatellite = 4500
vSatellite = vector(0,3.074e3,0)
pSatellite = mSatellite*vSatellite

#Time and time step
dt = 10
t = 0

#MotionMap/Graph

#Calculation Loop
while t < 60*365*24*60*60:
    rate(500)

    r = Satellite.pos - Earth.pos
    Fgrav = -G*mEarth*mSatellite*r/mag(r)**3

    Fnet = Fgrav

    pSatellite = pSatellite + Fnet*dt
    Satellite.pos = Satellite.pos + pSatellite/mSatellite*dt

    parrow.pos = Satellite.pos
    parrow.axis = pscale*pSatellite

    if mag(r) < Earth.radius:   ##IGNORE THIS LINE
        break                   ##IGNORE THIS LINE
    
    t = t + dt
