Search code examples
c#physicsfarseer

Reproducing gravity physics results with different timesteps


I'm writing a physics-based game which has planets with gravity acting upon various objects such as missles. (Using the Farseer Physics engine)

For the main gameplay, I am using a single physics simulation with a fixed timestep. This is all well and good, works beautifully.

Here's the problem. I'm using a second physics simulator with a larger timestep in order to project certain projectile paths into the future. Basically a parallel universe containing the planets and other static, gravity producing entities (Because I'm running these projection simulations in realtime, it needs to be fast, hence a larger timestep).

It's producing slightly different results.

Here's the basic code that is executed per timestep:

 Vector2 force = GravityStrength / centerToCenterDist.LengthSquared() /  Math.Sqrt(centerToCenterDist.LengthSquared()) * body1.Mass * body2.Mass * centerToCenterDist;

//GravityStrength is in addition to the Mass calculations

My parallel universe timestep is currently (5.0 * timestep).

I made an attempt to correct for the different in results by altering the results thus:

force = (force * (timestep+1))

My question: Is it possible to duplicate the results of the main simulator using a different timestep in the parallel simulator?

My math is not very good, so I'm having trouble thinking the problem through for possible solutions. I'm guessing it's not possible due to the non-linear type of equations involved.
If that's the case, is there a reasonably accurate way to get close results?


Solution

  • This is a math, rather than physics problem, but the answer is no. The simulation (any simulation) is an approximation and will be highly dependant on a few variables.

    In this case, it looks like a basic Euler method simulation. What you're seeing is differences in the global truncation error for the two simulations - in other words, each simulation has inherent, divergent error characteristics.

    You should see, for example, far more divergent simulations in 'near approach' cases (when two bodies deflect significantly, the error will be greater). You won't be able to correct it, because the correction would be more complex (ie computational power required) than the two models combined.