Search code examples
functionmathtimeglslorbital-mechanics

Planet position by time


I want to implement a gravity system in shadertoy without using any storage/buffer. So I can't save any variable and my animations must be a function of time. Is it possible to make a function of time to calculate the current position of the planet?!

I'm confused at all, because the next position depends on the current velocity and the current velocity depends on the former acceleration and that depends on former position. Is it theoretically implementable as a function of time?

The more general general question is that are can such semicircular relations be subject to be a regular function?

Initial values

Formulas f(x)=? as simple form

This function has the above problem, because f(x) depends on the former values of the function.

Note that planets aren't located in circular and stable orbits. But they have initial position and velocity.


Solution

  • A time function is possible only if you use Kepler's equation instead of a gravity simulation...

    That is doable only if you have stable orbits and note it’s just approximation of the true trajectory.

    See related:

    You can do a hybrid approach where you use Kepler for stable orbits and once interaction is triggered (by close proximity of objects) you convert back to the gravity model, compute the interaction result and convert back to Kepler (I assume that is how KSP is doing it).

    So you should have a list of Keplerian trajectories with their time duration for each body and then just use the correct one for queried time...

    So when putting it all together, I would:

    1. compute initial Kepler trajectories

      so compute points on a single orbit and obtain orbital parameters from it

    2. compute close encounters

      so times when bodies are near each other (similar to intersection of ellipses) see similar (but easier) problem:

      Also this might greatly help with elliptic encounters computations:

    3. for each encounter recompute the gravity model and create a new Kepler trajectory

      Add it to list of body trajectories that will be valid after time of encounter...

    4. If any encounter up to some time limit found, go to #2

    Now if you want to know where the body is at time t, just look to its list of Keplerian trajectories, use the one that has its valid time >= t while valid time is also smallest and just compute your position, speed or whatever you need...