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.0 # To change initial speed of the Earth from its circ.value 29900 m/s, # factor=1.4142 makes parabolic orbit (E=0) sun = sphere() sun.pos = vector(0,0,0) sun.radius = 3e10 sun.color = color.yellow sun.mass = 2e30 sun.p = vector(0, 0, 0) * sun.mass earth = sphere() earth.pos = vector(1.5e11,0,0) earth.radius = 2e10 earth.color = color.green earth.mass = 6e24 earth.p = vector(0, factor*29900, 0) * earth.mass dist = sun.pos - earth.pos force = 6.7e-11 * sun.mass * earth.mass * dist /mag(dist)**3 earth.orbit = curve(color=earth.color, radius = 2e9) farrow=arrow(pos=earth.pos,axis=2.0e-12*force) dt = 86400 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) farrow.pos=earth.pos farrow.axis=2.0e-12*force print "DAY:",t/86400