When I run my code the earth seems to tend towards a limit instead of orbiting round the sun, am I missing equations or is there something wrong with my code?
Here is the error I get:
Warning (from warnings module):
File "C:\Python32\lib\site-packages\visual\visual_all.py", line 52
return numpy(x)
RuntimeWarning: invalid value encountered in sqrt
Here is the code I have written:
from visual import *
def SUVAT(A,B):
global EarthFinalV
global Acceleration
EarthFinalV = sqrt((A) + 2*Acceleration*(B))
GravitationalConstant = 1
Sun = sphere(pos=(0,0,0), radius=10, color=color.red,
make_trail=True)
Earth = sphere(pos=(50,0,0), radius=5, color=color.yellow,
make_trail=True)
Sun.mass = 50
Earth.mass = 10
EarthInitialV = vector(0,1000,0)
EarthFinalV = vector(0,0,0)
while True:
rate(1)
Distance = Earth.pos - Sun.pos
GravitationalEquation = (GravitationalConstant*Sun.mass*Earth.mass) / mag(Distance)**2
Acceleration = GravitationalEquation/Earth.mass
SUVAT(EarthInitialV,Distance)
Earth.pos = Earth.pos - EarthFinalV