-1

I have to create a simple simulation of the Earth revolving around the sun. I can't use spherical coordinates, I have to use gravitational energy and velocity equations So far I have this:

earth = sphere (color = color.green, radius = 10**6)
sun = sphere (color = color.yellow, radius = 10**7)
earth.mass = 5.972*10**24 
sun.mass=1.989*10**30
d=1.496*10**8
v=(2*math.pi*d)/(3.154*10**7)
earth.velocity = vector(0.0, 0.0, -1*v)
earth.pos = vector(d, 0, 0)
sun.pos = vector(0,0,0)

dt = 50000
t = 0.0

P=0    
while True:
rate(400)
    f=(6.667*10**.11)*((earth.mass*sun.mass)/d**2)
    P = P + f*dt
    earth.velocity = P/earth.mass
    earth.pos = earth.pos + earth.velocity*dt
    t=t+dt

I don't know if I am missing something from the physics side or the coding but when I run it nothing shows up. Thanks in advance!

1 Answers1

0

Two issues: Your rate statement must be indented, and with the momentum P initialized to 0 the Earth should fall into the Sun.

user1114907
  • 972
  • 8
  • 15