-4

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",&timestep);

    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++;

    }
Spektre
  • 49,595
  • 11
  • 110
  • 380
Sangam
  • 86
  • 8

1 Answers1

0

You will not be able to get this working without understanding the physics.

First, forget about forces, accelerations and angular velocities; try to get one object to move with constant velocity. First like this:

x = x_0 + v_x t

(assuming that x = x0 at t=0), then like this:

x_new = x_old + v_x delta_t

Now apply a constant acceleration, so that v changes:

x_new = x_old + v_x_old delta_t + (1/2) a_x (delta_t)^2
v_new = v_old + a_x delta_t

Now the object should behave like a thrown ball, falling to the ground.

Once that's working, try using a gravitational acceleration toward a fixed point in space, inversely proportional to the square of the distance:

a = g/r^2
a_x = -a x/r
a_y = -a y/r

Once that's working, you can try two objects exerting force on each other.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Thank you for the reply. I tried the above steps and am getting the result.I am changing my initial input to velocity in x-direction and y-direction separately. But I do not know how to proceed further. It would be of great help if you could explain further. – Sangam Sep 15 '15 at 06:07
  • @Sangam: Further than what? Did you succeed at all of these steps? What are you having trouble with? – Beta Sep 15 '15 at 08:34
  • Yes. I could get output for your steps. But I need to find distance between two revolving satellites every 't' seconds. – Sangam Sep 15 '15 at 08:40
  • @Sangam: If you are calculating their locations correctly (according to the last step), then you can calculate the distance between them (every t seconds, or whenever you like) by the Pythagorean theorem. I suspect that you haven't actually gotten the above steps to work. – Beta Sep 15 '15 at 14:02
  • I have coded the above mentioned steps. I do not understand as to how circular satellite revolution is handled using the above linear equations. Do the x_new and y_new positions obtained from the above formulae follow a circular path? I got increasing values like 25,125,325,625 and so on for x_new and y_new taking v_old_x and v_old_y as 20 and x_0 as 25 and on plotting, i got a linear line and not a circular path . – Sangam Sep 15 '15 at 14:35
  • @Sangam Which was the first step to give unexpected results? And can you give a **complete, minimal example** of it? – Beta Sep 15 '15 at 14:44
  • I have added the code to my post. Initially I had commented the acceleration part of it and got increasing x,y values. In the above code, x,y values do not change. That is, x=25, y=25 even after the calculation.. – Sangam Sep 15 '15 at 15:19
  • Are you telling me that your code gave sensible results when you did the "now apply a constant acceleration" step? – Beta Sep 15 '15 at 16:04
  • yes. I got a linear line passing through the origin. – Sangam Sep 15 '15 at 16:15
  • @Sangam: That is not a sensible result, and I don't know how you got it with `delta_t=0;` and never updated. In the previous step, did you see the object travel along a curved trajectory, like a thrown ball? As I said at the beginning, if you don't take the time to understand the physics, you will not be able to get this to work. – Beta Sep 15 '15 at 16:22
  • Ok. Thank you for helping. I didnt get a curved trajectory. I will try finding the error. – Sangam Sep 15 '15 at 16:28