|Home||Nice graphics are good to draw attention, but underneath, the physics do the real fun job.|
This page contains programming tips for your physics code.
2nd ORDER INTEGRATION ACCURACY FOR ALMOST FREE
What you often see is integration steps that go like:
This is a Euler step. If you've read David Baraff's papers on integration, you may have noticed that the Euler integration is just the first part of an infinite Taylor series. The above formula has an error of O(h), meaning not too accurate in practical terms. It will explode quite quickly.
An alternative is RK4 (Runge-Kutta fourth order), which takes you to O(h^5), but that requires some work. A shortcut you can take to get to O(h^2) is realising you're calculating the 2nd order derivative of 'pos' with the force calculations. This means you can use more of the Taylor series for free. I won't outline the exact Taylor series, but here's the result in code:
In math, this is like: x=x+f(x)*dt+0.5*f'(x)*dt^2. Ofcourse it will be a good idea to precalculate t*t (even if you have variable timesteps).
This is used in some places in Racer v0.4.9.
(last updated November 13, 2012 )