Satellite Orbiting Earth Code

The code for satellite orbiting Earth is here:

Earth=sphere(pos=(0,0,0),
 radius=R,
 color=color.blue)

h=3.6e7

object_pos_init= vector(R,0,0)

object= sphere(pos=object_pos_init,
 radius=R/5,
 color=color.white,
 make_trail=True,
 trail_type="points",
 interval=10)

v_esc= sqrt(2*G*M/R)
 v0= v_esc
 v= vector(0,0.95*v0,0)

T_circ= (2*pi*(R+h)/v0)
 dt= 0.001*T_circ

F=vector(0,0,0)
 p= m*v
 r= (object.pos-Earth.pos)

t=0
 while t<10*T_circ:
 rate(1000)
 F= G*M*m/mag2(r)*(-norm(r))
 p= p+F*dt
 v= p/m
 object.pos = object.pos+v*dt
 r= (object.pos- Earth.pos)
 t= t+dt

sqrt(G*M/(h+R))

Here is how it runs:


Continue reading “Satellite Orbiting Earth Code”

Advertisements