title: How to find distance between two satellites in space?
body: <p>I want to write a C program to find the distance between two satellites in space every <code>t</code> seconds. My initial inputs are:</p>
  
  <ul>
  <li>initial velocity</li>
  <li>mass</li>
  <li>radius</li>
  <li>position (x,y coordinates)</li>
  </ul>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>As per info from search engines, double integrating the acceleration gives the distance between the 2 satellites.</p>
  
  <p>I am calculating the new positions using:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I am using:</p>
  
  <pre><code>linear acceleration = Net force/massOfSat1;
  angular acceleration = linear acceleration/radiusOfSat1;
  </code></pre>
  
  <p>to compute <code>a</code> and </p>
  
  <pre><code>v_x =initial_angular_velocity_x + a(delta t)
  v_y =initial_angular_velocity_y + a(delta t)
  </code></pre>
  
  <p>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.</p>
  
  <p>Is this the correct way of applying the concept and formula?</p>
  
  <p>Here is a nice url which looks similar to what I am planning to do:<br>
  <a href="http://www.science-animations.com/support-files/gravitasieplaneteb.swf" rel="nofollow noreferrer">http://www.science-animations.com/support-files/gravitasieplaneteb.swf</a></p>
  
  <p>The code is as follows:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>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",&amp;timestep);
  
      printf("\nEnter the velocity x component of satellite 1:");
      scanf("%lf",&amp;v_x_old1);
  
      printf("\nEnter the velocity y component of satellite 1:");
      scanf("%lf",&amp;v_y_old1);
  
      /*printf("\nEnter the velocity x component of satellite 2:");
      scanf("%lf",&amp;v_x_old2);
  
      printf("\nEnter the velocity y component of satellite 2:");
      scanf("%lf",&amp;v_y_old2);*/
      r = 10.00;
      x_old1 = 25.00;
      y_old1 = 25.00;
      a_x1 = 0.0;
      a_y1 = 0.0;
      while(i&lt;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++;
  
      }
  </code></pre>