I want to write a C program to find the distance between two satellites in space every t
seconds. My initial inputs are:
- initial velocity
- mass
- radius
- position (x,y coordinates)
for both satellites. Since I have initial positions, that is, x,y coordinates (actually x,y,z coordinates but for simplicity I am taking x,y) of both the satellites, using Pythagoras theorem I can find the initial distance between the 2 satellites.
Then I calculate the force exerted by Satellite 1 on Satellite 2 using Newton’s universal law of gravitation. The 2 satellites are continuously revolving in 2 different circular orbits (say, one vertical to the earth and the other horizontal and same radius such that they may collide).
As per info from search engines, double integrating the acceleration gives the distance between the 2 satellites.
I am calculating the new positions using:
x_1 = x_0 + v_x delta_t + (1/2)a (delta_t)^2 and y_1 = y_0 + v_y delta_t + (1/2) a (delta_)t)^2
I am using:
linear acceleration = Net force/massOfSat1;
angular acceleration = linear acceleration/radiusOfSat1;
to compute a
and
v_x =initial_angular_velocity_x + a(delta t)
v_y =initial_angular_velocity_y + a(delta t)
This formula does not give a valid distance as it keeps on increasing but I expect that the distance increases and decreases as it is a circular motion and the satellites can come near or go far as well. I feel that I am going wrong in using a suitable formula for acceleration.
Is this the correct way of applying the concept and formula?
Here is a nice url which looks similar to what I am planning to do:
http://www.science-animations.com/support-files/gravitasieplaneteb.swf
The code is as follows:
const double g = 9.8;
void main(){
int delta_t=0,i=0, timestep=0;
double v_x_old1,v_y_old1,v_x_old2,v_y_old2,a,a_x1,a_y1,v_x_new1,v_y_new1,x_new1,x_old1,y_new1,y_old1,r;
printf("\nEnter the time interval delta t:");
scanf("%lf",×tep);
printf("\nEnter the velocity x component of satellite 1:");
scanf("%lf",&v_x_old1);
printf("\nEnter the velocity y component of satellite 1:");
scanf("%lf",&v_y_old1);
/*printf("\nEnter the velocity x component of satellite 2:");
scanf("%lf",&v_x_old2);
printf("\nEnter the velocity y component of satellite 2:");
scanf("%lf",&v_y_old2);*/
r = 10.00;
x_old1 = 25.00;
y_old1 = 25.00;
a_x1 = 0.0;
a_y1 = 0.0;
while(i<25){
//satellite 1
//x_new1 = x_old1 +( v_x_old * delta_t);
//Now apply a constant acceleration, so that v changes:
x_new1 = x_old1 + (v_x_old1 *delta_t) + ( (1/2)* a_x1* (pow(delta_t,2.0)));
v_x_new1 = v_x_old1 + (a_x1* delta_t);
x_old1 = x_new1;
v_x_old1 = v_x_new1;
y_new1 = y_old1 + (v_y_old1 *delta_t )+ ((1/2)* a_y1* (pow(delta_t,2.0)));
v_y_new1 = v_y_old1 + (a_y1* delta_t);
y_old1 = y_new1;
v_y_old1 = v_y_new1;
a = g/pow(r,2.0);
a_x1 = (-a* x_new1)/r;
a_y1 = (-a* y_new1)/r;
printf("\n a_x1 = %0.3lf",a_x1);
printf("\n X-coordinate = %0.3lf, Y-coordinate = %0.3lf",x_new1,y_new1);
delta_t += timestep;
i++;
}