#Calculate the distance between two satellites that are initially
#aligned with the "sun" M, given M, r1, r2, and the elapsed time t.
#Get the necessary constants and functions from numpy
from numpy import pi, cos
#To import all the numpy functions, you could also use #from numpy import *
#gravitational constant in mks units
G = 6.67300e-11 # m3 kg-1 s-2
#get r1
r1 = input('Enter radius r1 in metres and press return. ')
#get r2
r2 = input('Enter radius r2 in metres and press return. ')
#get M
M = input('Enter mass M in kilogramsand press return. ')
#get t
t = input('Enter elapsed time t in days and press return. ')
#T1 in seconds
T1 = ((4*pi**2)*r1**3/(G*M))**0.5
#T2 in seconds
T2 = ((4*pi**2)*r2**3/(G*M))**0.5
#Convert t in days to t in seconds
t_seconds = t*24.0*60.0*60.0
#Calculate angular displacement
delta_theta = 2*pi*t_seconds*(1/T1-1/T2)
#use cosine law
delta_r = (r1**2+r2**2-2*r1*r2*cos(delta_theta))**0.5
seconds_in_year = 365.0*24.0*60.0*60.0
#For output purposes, calculate periods in years.
T1_years = T1/seconds_in_year
T2_years = T2/seconds_in_year
#For output purposes, calculate angular separation in degrees.
#Use the "%" operator to make the angle fall between 0 and 360 degrees.
delta_theta_degrees = delta_theta*180.0/pi
delta_theta_degrees = delta_theta_degrees%360
#print out results
print 'You set M =', M, 'kg, r1 =', r1, 'm, r2 =', r2, 'm, t =',t,'days.'
print 'Orbital period 1 is', T1_years, 'years. Orbital period 2 is', T2_years, 'years.'
print 'Angular separation is', delta_theta_degrees, 'degrees.'
print 'The distance between the satellites is', delta_r/1000,'km.'