Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  		block.v += a * frameRate;
 		block.x += block.v * frameRate;
"If you use Euler then you are a bloody idiot" http://gafferongames.com/game-physics/integration-basics/

Based on own experience if you replace euler with RK4 you can multiply your timestep with 10x and still get more accurate results. Once you start adding constraints this is a must or your constraints will disassemble almost instantly with euler, while rk4 barely requires any after-adjustment to keep the constraints intact.

http://gafferongames.com/game-physics/fix-your-timestep/ would also be a nice improvement to the simulations.



That's about right, but note that both Euler and RK4[1] have the same kind of "whiplash" failure modes when faced with out of band inputs. So RK4 is good, and simple, and worth learning. But as you point out it's really just a performance improvement over naive Euler integration[2].

Basically, don't get hung up over pedantry here. Euler is extremely simple, trivially verifiable and works well in a large number of domains. Demanding everyone who wants to do a simple physics model crack open a textbook is, I think, missing the point.

[1] Fourth order Runge-Kutta integration, a common and reasonably simple algorithm for numeric integration. See: http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods

[2] Euler is the simplest possible integration algorithm most people learn in grade school, essentially: compute your derivatives, multiply by the timestep and add to the current value, and repeat. It falls down and produces wild output when the derivative*timestep product is not small in comparison with the current value.


Thanks! This article and the other Physics in JS article mention that we're using Euler only because it's the easiest for a student to understand. The article also mentions that the next post will be dedicated to exploring the different integration solvers.

My guess is that the original commenter just skimmed through the code without reading any of the prose ;)


You're right!

However, both in this article and a previous article I point out that Euler is the least accurate of the numerical integration methods.

I also mention several times that there will be an upcoming article dedicated to exploring other integration techniques.

Additionally, in the previous article I mention that the reason we're using Euler's method is because it's the easiest for a student to look at and understand at a glance, not because it's the best or only technique.

Finally, other articles mentioned that we are not going through these exercises with game dev or optimization in mind. These are educational articles about physics and physics alone.

But as I said, you're right. Anywhere outside of the scope of education, Euler's method is not the best choice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: