from visual import * #Constants G = 6.7e-11 day = 24*60*60 year = 365*day pscale = 1e11/1e29/3 fscale = 1e11/1e22/4 #Objects Sun = sphere(pos=vector(0,0,0), radius=1e10, color=color.yellow) Earth = sphere(pos=vector(1.5e11,0,0), radius = 5e9, color=color.cyan) scene.autoscale = False parr = arrow(color=color.red) farr = arrow(color=color.green) Sun.m = 2e30 Earth.m = 6e24 #Initial values Sun.p= vector(0,0,0) Earth.p = Earth.m*vector(0,2*pi*Earth.pos.x/year,0) Earth.trail=curve(color=Earth.color) Earth.trail.append(pos=Earth.pos) deltat = day t=0 #Loop for repetitive calculations while True: # t < year: rate(100) r = Earth.pos - Sun.pos rmag = mag(r) rhat = r/rmag Fnet = (-G*Earth.m*Sun.m/rmag**2)*rhat Earth.p = Earth.p + Fnet*deltat Earth.pos = Earth.pos+Earth.p/Earth.m*deltat Earth.trail.append(pos=Earth.pos) parr.pos = Earth.pos parr.axis = pscale*Earth.p farr.pos = Earth.pos farr.axis = fscale*Fnet t = t + deltat