Home > Blockchain >  Physics/Vectors Question - Solar System Movement, Vectors and Scalar calculations
Physics/Vectors Question - Solar System Movement, Vectors and Scalar calculations

Time:09-29

I'm dealing with a question for class that is asking me to mimic the movements of planets/moons/asteroids within a solar system in a 3D space. We started early the semester with vectors, masses, and forces, so I'm still trying to grasp it.

*My issues are detailed below on step 4 and 5. Let me know if I got anything wrong along the way. Any input and guidance would be greatly appreciated.

  • Info Given

Each object in space has the following:

  • mass
  • position vector <x, y, z>
  • velocity vector <x, y, z>

I have to use Newton's Law of Universal Gravitation:

F = G * mass1 * mass2 / distance^2
  • Question

Given time t update the position and velocity of each object in space. So if t is 10 seconds, where would those objects be in space at that given time?

I'm told to treat acceleration as constant throughout t. And not to worry about object collisions and that the objects may be extremely small, for simplicity's sake. Given objects in space may be from 1 to 100.

  • My Progress So Far

I'm not sure if I'm doing it right so far but here's the steps I'm taking so far:

Step 1: If it was 2 objects then I'd use the force formula as it as. But since it's X amount of objects I'm going through each object and I'm calculating the Force between itself and every other object. I'm adding those up to a Net Force.

Step 2: I'm calculating my Acceleration:

a = Net Force / Mass

Step 3: Next I calculate the final velocity:

V = u a*t u = initial velocity

Step 4: Calculate the final position of the object:

s = s0   u*t   1/2*a*t^2 

s0 = initial position, u = initial velocity

Step 5: repeat the process on the rest of the objects

My problem is on step 4 and 5. My positions and velocities are vectors. but the acceleration is a scalar, so I know I just can't add that up to the vectors. So what do I do here? Do I do the calculation on each vector component then put all the components back into the new final velocity and final position vectors? I'd really appreciate the help and any input.

CodePudding user response:

First see this QA:

Your steps are completely wrong for dynamic n-body orbital mechanics !!!

Because your bodies are moving along curves You need to iterate the integral using Newton D'ALembert integration instead of computing the whole thing at once as the directions and forces are changing along the way or else your orbits would be distorted or even rotating or deviating toward sun or even escape in time. There are also integration methods preserving energy for this...

Also You have to compute all the forces from all bodies before any computation changes the positions of your bodies otherwise you will implement wrong directions as some bodies already computed are in new positions and others are not yet. This usually cause problems for close proximity bodies like moons and or fly by ...

I use this logic instead:

  1. for each body you need to have these:

    struct _body
     {
     double mass;
     dvec3 pos; // position
     dvec3 vel; // velocity
     dvec3 acc; // acceleration
     } body[n];
    

    also use at least 64bit double floating point for this. If you have more its even better as even 64bit float is at its limits for computations like this.

  2. for each body compute acceleration

    so simply sum up all the accelerations for each body

    for (i=0;i<n;i  ) body[i].acc = dvec3(0,0,0);
    for (i=0;i<n;i  )
     for (j=i 1;j<n;j  ) 
      {
      dvec3 d = body[i].pos - body[j].pos;
      dvec3 F = G * body[i].mass * body[j].mass * d / pow(length(d),3);
      body[i].acc -= F/body[i].mass; // the same force is aplied to both bodies
      body[j].acc  = F/body[j].mass; // just in reverse direction
      }
    

    the d / pow(length(d),3); will give you vector in direction of d and size of 1/d^2. where length(d)=sqrt(d.x*d.x d.y*d.y d.z*d.z) This term converts your scalar equation into vector one ...

    You might also add some sanity check for the d size so you avoid the division by too small or zero value once your bodies crash into each other ...

  3. now you apply the changes for each body

    for (i=0;i<n;i  )
      {
      // Newton D'ALembert integration
      body[i].vel  = body[i].acc*dt; // this is instead of V = u   a*t
      body[i].pos  = body[i].vel*dt; // this is instead of s = s0   u*t   1/2*a*t^2
      }
    

    where dt is your iteration time step for example 0.1 sec (or timer interval or elapsed or simulated time step) iteration time step greatly impacts precision So if you need more precision I recommend to use the precision enhancing trick from the linked answer above it hugely improves things without significantly lowering dt.

    Also note is crucial that steps #2 and #3 are in separate loops do not merge them together!!!

  4. go to #2

    so you repeat steps #2,#3 during your simulation using timer, or thread with some sleep(dt) or whatever mechanism your simulation engine uses for timing.

CodePudding user response:

If professor told you to treat acceleration as constant throughout the time steps then do so and also take it as vector which doesn't change with respect to time.

your Acceleration can be

vec3 acc = vec3( accVal, accVal, accVal );

this will give you a acceleration that is constant on all three Axis.

  • Related