2

Im trying to make small 2d solar system orbit simulator as hobby project and im having some issues with finding orbital info. (a, e, time to apo, time to peri, T).
I have readen some infos, articles, laws and even found some intersting research articles but im having troubles with understanding these and connecting these together.

My issue is - i cant get any orbit info from object state. Or, better to say, i dont know how :)
I want to get current orbit info each tick.

I have simplified solar system model - objects being attracted by stars. Thats it. No interactions between stars or objects itself => stars are at constant position. In this very basic example - only one star and one object.

My formula is to find attraction force is:

var dist = object.getPos().dist(fromStar.getPos()); // distance to star, can be centerOfMass if needed.
return 1 / Math.pow(dist, 2) * object.getMass() * this.gravitationalConstant; //: F = 1 / dist^2 * M * G

and this is my acceleration formula:

  public function getTotalAttractionVector(object: ObjectState): Vec2 {
        var result = new Vec2();
        for (star in stars) {
            var dir = object.getPos().getDirectionTo(star.getPos()); // normalized
            var force = this.getAttractionForce(object, star); // from the formula above

            result.addMut(dir.mulScalarMut(force));
        }
        return result;
    }

The info what i have at the starting of each tick:

1. current position, current vel. Both as vector.
2. position from last tick, vel from last tick.
3. center of mass of solar system.
4. object mass
5. G
6. F from formula above and acceleleration as vec

I also have roughly simulated predicted points for next n ticks, they arent very precise (since my simulation at the moment isnt depending on any kind dt) but maybe there way to use them.

Until, my closest approach is these formulas;

E = (v^2)/2 - G*M/r

where v - magnitude of a vel vector, M = mass of obj, r = distance to center of mass, in this case distance to single star, G = grav. constant

a = -G*M/2E 
e = sqrt(1 - r^2/(a(2E + GM))) 

With this approach, my semi major axis (a) value from the formula above is correct only as my orbit of a object is approaching to circular. In case if my orbit is elliptical or not circular, wrong values are occuring. For example, a = 500 while distance to star being more than 800. If im understanding the idea of semi major axis correct, this can not occur at all. So i guess this is wrong too.

Im sorry for my bad english and for little overload with info, but maybe someone can help me, show where my logical misstakes or maybe even rough idea do this correct. Thanks! :)

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
Z1nK
  • 21
  • 3
  • 1
    see [Is it possible to make realistic n-body solar system simulation in matter of size and mass?](https://stackoverflow.com/a/28020934/2521214) and all sublinks in there... what you should do is simulate one tropical year of your body (remembering some points) and fit the ellyptic (or whatever) trajectory to match those points (I am sure I answered something like that before in more detail IIRC someone also post table of equations to convert between state and orbital parameters but can not find the QA anymore :( ...) – Spektre Feb 02 '23 at 09:03
  • Just simulate tropical year? This is very rough. What if eccentricity of orbit is very big? It would take too much cpu time to get single orbit. – Z1nK Feb 02 '23 at 09:47
  • You can adjust the time step based on distance to local star (or center of mass) and `|velocity|` but yes you can expect long computation in edge cases ... – Spektre Feb 02 '23 at 14:29

0 Answers0