Search code examples
mathgame-physicsnumerical-methodsnumerical-integrationverlet-integration

The time-corrected Verlet numerical integration formula


There is a commonly used verlet-integration formula on the web by Johnathan Dummer, called Time-Corrected Verlet. However I've read several forum posts, that people get weird or unexpected results with it in certain conditions.

Formula by Johnathan Dummer:

x1 = x + (x – x0) * dt / dt0 + a * dt^2

There is also a stackoverflow answer, which states that Dummer's time-corrected formula is broken and the poster presents his own derivation as the correct one.

Suggested correct formula by a stackoverflow answer

x1 = x + (x – x0) * dt / dt0 + a * dt * (dt + dt0) / 2

Well, is Dummer's formula really broken? If yes, is the derivation of the poster better?

PS: It is also weird that Dummer uses the verlet integration formula x1 = x - x0 + a * dt^2 on his website instead of the correct x1 = 2x - x0 + a * dt^2.


Solution

  • The wikipedia page Verlet integration - Non-constant time differences presents the two formula, without referenced. I've not checked the derivation myself but the reasoning for the second improved formula looks sound.

    I've downloaded Dummer's spreadsheet and modified one of the formula to use the correction. The results are much better.

    Comparison of methods

    The exact results are in yellow, we see that just using the normal Verlet algorithm with fluctuating frame-rate is bad. Dummer's time-correct varient in red is pretty good, but a little off. The dark green version with the improved correction is much better.

    For projectiles under gravity which has a quadratic solution you may find that the improved version is exact. When the degree gets a bit higher it will vary from the true path and it might be worth testing to see if we still get a better approximation.

    Comparing methods for sin

    Doing the same calculation for a sin curve shows the improved method is considerably better. Here Time-correct Verlet is drifting quite a bit. The improved version is better, only a little bit off the exact answer.


    For the PS. Note that if you set dt=dt0 in the TCV formula

    x1 = x + (x – x0) * dt / dt0 + a * dt^2
    

    you get

    x1 = x + x – x0 + a * dt^2
       = 2 x – x0 + a * dt^2
    

    the original Verlet formula.