Euler Method

Derivation of forward euler method for a small collision study I wanted to start simply and this is the most basic, explicit method for numerically integrating an ODE.

Derivation


Recall the limit definition of a derivative:

\[ {f^{\prime}(x)} = \lim_{h \to 0} \frac {f(x + h) - f(x)}{h}\]

Where \(h\) is some infinitesimal change in a continuous variable.

For a simulation, \(h\) is some small, but discrete time step associated with the physics tick/ cycle.

\[f^{\prime}(t) \approx \frac {f(t + {\Delta t}) - f(t)}{\Delta t}\]

Algebraically rearranging for the function at the next time step \(f(x + {\Delta t})\):

\[f( t + \Delta{t}) \approx f(t) + f^{\prime}(t) \Delta{t}\]

That is to say, we can approximate the value of the next step of a function if we have its value and its derivative value at the current time step.

We can apply this for the motion in a simulation after resolving the acceleration of a cycle by working backward:

Given position \(\vec r\):

Velocity: \[\vec v = \frac{d}{dt} \vec r\]

Acceleration: \[\vec a = \frac{d}{dt} \vec v\]

\[\implies v(t + \Delta t) \approx {v^{\prime}(t)} {\Delta t} + v(t)\]

\[v(t + \Delta t) \approx a(t) {\Delta t} + v(t)\]

Similarly: \[r(t + \Delta t) \approx {r^{\prime}(t)} {\Delta t} + r(t)\] \[r(t + \Delta t) \approx v(t) {\Delta t} + r(t)\]

// After resolving acceleration from physics constraints
rigidBody.velocity += acceleration;
rigidBody.position += velocity;

Note: We're using derivatives, so smoothness is implied for whatever we're trying to look at. Thus, the same result can be found by using a Taylor series expansion around the next time step and truncating second order and higher terms. This is also illustrative of the limitations of the Euler method, i.e. stability; error is proportional to the time step squared (second order and greater terms are dropped) Compare this with an alternative numerical technique such as verlet integration where the error rate is proportional to the time step quadrupled.