Skip to main content
gamedev.net
🔒 Locked

integration

Started by Humbaba May 6, 2004 at 2:22 AM 3 replies 850+ views
Original Post
Humbaba
Humbaba
Maybe someone can explain this one. I hear people always talking about best methods for performing your integration from accel -> velocity -> position. There''s your basic Euler methods, and then some more fancy Runge-Kutta (sp?) shyte. Apparently, more accurate integration algorithms keep your physics stable allowing you to model stiffer springs and collisions without needing to run your physics any faster, e.i. without using a smaller time interval and updating your physics more often. But my argument is this: there''s no replacement for having the smallest possible time interval. If you have a really stiff spring, it has a really high natural frequency, and unless your physics is iterating fast enough to capture that oscillation, you''ll go unstable or get garbage results no matter how wonderful your integration method is. And 60Hz is pathetically slow. For my physics engine (www.xlife.org/atomic) I used the most basic euler integration method, but my physics runs super fast so I can use super-stiff springs. So someone correct me if I''m wrong, but I say, screw all your fancy Runge-Kutta stuff and just update your physics at a higher frequency. Cheers, Stephen
shaobohou
shaobohou
What you said is all fine, provided that you can afford to update at super fast rate.

But why waste the cpu cycles when you can use RK4 with timesteps 10000 times as big and acquire the same degree of accuracy with only (roughly) 4 times the computational cost.

RK4 is more stable than you think, regardless of the case, it will work better than euler. Naturally, you would still run RK4 as fast as you can in realtime, I think people who goes on about using larger timestep are probably not bothered about real time applications.

[edited by - shaobohou on May 6, 2004 7:46:43 AM]
Just because it is not nice, doesn''t mean it is not miraculous.
szinkopa
szinkopa
Check this out:
http://www.math.sc.edu/~sharpley/math242/Compare_E_ImE_RK4.pdf

It compares Euler, Corrected Euler and RK4, showing the error with different timesteps and the neccesary number of operations per frame. You can see the Euler with timestep 0.001 sec is still worse than RK4 with timestep 0.1 sec. And RK4 need only 4 times more operations than Euler.
So this all is for accuracy.
And note that with timestep h, RK4 (and RK2 too) takes a sample of the force at the middle of the timestep, that''s why it can handle with the same timestep more frequency well.
Maybe your physics engine with Euler is stable, but it''s much unaccurate than with RK4 it would be even with bigger timestep.

As for high frequencies, I think the timestep should be adjusted to the higher frequency that may occur in your physics. You can also use varying timestep by demand, or varying integration methods also by demand.

So when using better than Euler, the main advantage is accuracy, and the secondary is stability.
FReY
FReY
Also, if your time-step is directly related to the framerate (alot of people do this), then RK4 is more stable under fluctuating framerates too.
do unto others... and then run like hell.
LilBudyWizer
LilBudyWizer
With euler versus runge-kutta that isn't really a valid arguement. They are both explicit first order methods. You are only talking five lines of code versus one to calculate the next iterate. When it comes right down to it you are arguing the increased complexity of the code isn't justified by the increased accuracy or decreased computational cost. Both are just a couple of minutes to implement.

Hehe, make that explicit single-step methods since runge-kutta is 4th order.

[edited by - LilBudyWizer on May 6, 2004 9:48:19 PM]
Keys to success: Ability, ambition and opportunity.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.