0

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.

Mehran
  • 56
  • 1
  • 9

2 Answers2

2

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...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Thanks. Also answer my general math question that i added just now to the text, if you can. – Mehran Jun 20 '22 at 16:37
  • 1
    @Mehran The trajectory is ellipse parabolic or hyperbolic curve so yes it can be converted to such functions however only piecewise and usually the geometric shape of trajectory and time has non linear dependence (that is what Kepler's equation is all about) see: [Solving Kepler's equation](https://stackoverflow.com/a/25403425/2521214) ... time is converted to mean angle `M` and that is converted to real angle `E` or `V` depends on what ellipse equation you want to use – Spektre Jun 20 '22 at 16:56
1

Even in the case of the two-body problem (Newtonian gravitation), you can't express the position of a planet as a simple analytical function of time and you need to resort to numerical integration.

So I don't see how in a more general case you could compute positions without using variables.

  • Thanks Also answer my general math question that i added just now to the text, if you can. – Mehran Jun 20 '22 at 16:38
  • 1
    What? Don't you (YD) mean the three-body problem? Isn't the solution of the two-body problem that trajectories are conic sections? – Robert Dodier Jun 20 '22 at 17:28
  • @RobertDodier i don't understand these words . what do you mean by "three-body problem"? i just has heard two-body problem. – Mehran Jun 20 '22 at 18:10
  • 1
    @Mehran, 2-body problem = 2 bodies (planets, etc) interacting, 3-body = 3 interacting, n-body = n bodies interacting. Historically the analysis of planetary motions started with 2 and went on from there ... A web search for those terms will find some resources. – Robert Dodier Jun 20 '22 at 18:16
  • 1
    @RobertDodier: what's the dependency on time ? –  Jun 20 '22 at 18:47
  • 1
    Oh, yes, I forgot. The shape is simple to describe but the location on it is not. – Robert Dodier Jun 20 '22 at 22:22