from visual import * #Calculates Earth's orbit about the Sun, v^2=G Msun/r, gives v=29900 m/s, #using G=6.7e-11 Nm^2/kg^2,Msun=2e30 kg, r=1AU=1.5e11 m scene.width=800 scene.height=800 factor=1.2 # To change initial speed of the Earth from its circ.value 29900 m/s, # factor=1.4142 makes parabolic orbit (E=0) earth = sphere() earth.pos = vector(0,6.4e6,0) earth.radius = 5e5 earth.color = color.green earth.mass = 1 earth.p = vector(factor*7920, 0, 0) * earth.mass theta=0 c = curve(x=arange(-6.4e6,6.4e6,1e3),radius=1e5) # Draw a 1/2 circle (top) c.y=((6.4e6)**2 - c.x**2)**0.5 c = curve(x=arange(-6.4e6,6.4e6,1e3),radius=1e5) # Draw a 1/2 circle c.y=-((6.4e6)**2 - c.x**2)**0.5 sun = sphere() sun.pos = vector(0,0,0) sun.radius = 6.4e6 sun.color = color.yellow sun.mass = 6e24 sun.p = vector(0, 0, 0) * sun.mass sun.visible=0 dist = sun.pos - earth.pos force = 6.7e-11 * sun.mass * earth.mass * dist /mag(dist)**3 earth.orbit = curve(color=earth.color, radius = 1e5) parrow=arrow(pos=earth.pos,axis=5e2*earth.p) dt = 10 t=0 while 1: rate(100) t=t + dt dist = sun.pos - earth.pos force = 6.7e-11 * sun.mass * earth.mass * dist /mag(dist)**3 earth.p = earth.p + force*dt earth.pos=earth.pos + (earth.p/earth.mass)*dt earth.orbit. append(pos=earth.pos) parrow.pos=earth.pos parrow.axis=5e2*earth.p print 'DAY:',t/86400