Skip to content

About

Testing different numerical integration methods for acceleration/velocity of 2D bodies in Godot.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Repository files navigation

Description

Comparison of different numerical integration methods for acceleration/velocity of 2D bodies in Godot.

method symplectic1 error order variable Δt2 samples per step3
Basic Euler ❌ O(Δt) ❌ 1
Symplectic Euler / Rigidbody2D ✔️ O(Δt) ❌ 1
Velocity Verlet ✔️ O(Δt^2) ✔️ 14
Leapfrog ✔️ O(Δt^2) ❌ 14
Midpoint ❌ O(Δt^2) ❌ 2
RK4 ❌ O(Δt^4) ❔ 4
Forest Ruth ✔️ O(Δt^4) ✔️ 3
PEFRL ✔️ O(Δt^4)5 ✔️ 4

Testing scenarios:

  • Ballistic trajectory - constant acceleration
  • Orbital mechanics - acceleration depends on position
  • Harmonic oscillator - acceleration depends on position

Analysis (in progress) - A more detailed comparison based on this project research

References with more accurate mathematical descriptions of the techniques

Possible improvements

  • Error analysis compared to analytical solution for orbital scene
  • Yoshida integrator
  • Adaptive timestep techniques

Footnotes

  1. The system conserves energy if the underlying system does (ie. planets orbit does not change total energy on average) ↩

  2. Is the error constant with a variable timestep? While a workaround is to have a fixed timestep, this is still a preferred property that enables changing the speed of the simulation at runtime and integrating at higher timesteps to predict the future. This might just be a consequence of the first two properties, so take it with a grain of salt. ↩

  3. Actual number is doubled when integrating both acceleration and velocity. Note that this is not an accurate indicator of performance, but a ballpark estimate ↩

  4. Theoretically it's 2, but one sample can be cached from one frame to the next as it is the same value ↩ ↩2

  5. order is the same, but in practice PEFRL is 26 times (!!!) more accurate than FR (Forest Ruth) ↩

About

Testing different numerical integration methods for acceleration/velocity of 2D bodies in Godot.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Contributors

Languages