Putting changing differences in arrays

Hey all,

I'm trying to set up a simulation of orbit, and to find the way the forces work I need to find delta x and delta y for each planet in relation to all the others. I've set up arrays for x and y coordinates of the planets, but I'm having trouble finding a way to set up a loop that compares each x with each y and putting it into the result into an array that I can read from in an order that makes sense. So far, this is what I have:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
where N = number of planets

  int i = 0; int j = 0; int counter = 0;
       
      while (j < N){
       if (i != j){
             deltax[counter] = px[j] - px[i];
             deltay[counter] = py[j] - py[i];
             counter++;
           }
             i++;
       if (i == N){
             j++; 
             i = 0;
           }
       }


I'm sure theres oodles of problems with this, and any help is appreciated. It's one of those problems where as a human I can say "well just compare this and those" but when it comes to putting it into code I'm lost!
Any help would be appreciated.
Last edited on
Topic archived. No new replies allowed.