How do you integrate/differentiate when your programming? I know how to do it by hand, but not sure how to tell the computer to do it. I wouldve have thought that checking the power (p) and adding one and dividing by (p + 1) would be quite slow in real time. Any suggestions? Thank you
To be honest, I have never once had the need to do either- but I would be interested to know how that comes up in game programming.
Maybe Im going about it the wrong way, but Im trying to incorporate a physics engine. Assuming I have acceleration, I could integrate to find velocity and integrate velocity to find position. This could also be reversed by differentiation. However, when it comes to programming the actual thing, Im not sure if I should be integrating, or if theres another method that does the same thing. Sorry I dont use C++, I use blitz so Im not sure what the equivalent of that function is.
Take a look at numerical integration - lots easier than doing it symbollically. It is used in most physics engines. I use Verlet integration - easy and stable.
You don't need to make a symbolic integration engine, because you know beforehand what functions do you want to integrate. So, just calculate the primitives (or anti-derivatives or whatever you call them) and integrate knowing that integral(f'(x)) | (t1, t2) = f(t2) - f(t1) where f'(x) is the derivative of f(x). Or you could do numerical integration, which is what most people do.
Absolutely go with numerical solutions - integration, differentiation, solving ODEs, PDEs, Integral Equations, even solving equations for roots. Doing it symbolically would be a huge task (there are big software packages like Maple that do just that) and also very slow in a gaming physics engine. Solve the problem mathematically first, then look at what your game actually needs to do, then look at how you can do that much more quickly. Simple example: You want to calculate the parabolic path of a projectyle. Rather than actually finding the h(t) height equation for this, realize that in a parabolic path the velocity (i.e. the delta-h) increases/decreases in a linear fashion. So all you need to do is steadily decrease the delta-h and keep adding that to your current height. This way you accomplish with two additions which would otherwise take at least a quadratic function (not a huge difference, for sure, but this is just a simple example).
There are a good set of articles at Gaffer's site about integration in game physics. http://www.gaffer.org:8080/articles/ e.g. Why euler integration should be avoided Fixing your timestep Physics over the internet Hope this helps, Pete
Thanks. Does that site have a mirror, because it seems like its down EDIT: No worries, google cache to the rescue . This site looks very interesting.
I couldn't get the site to work when posting either, I just thought my connection was messing up (i have a dodgy gateway box...) Here are google cache links for those who are interested: Main articles page Integration basics Fix your timestep Physics in 3d Pete
Most of the people who incorporate basic physics actually use integration without even knowing it! The use a very basic form of integration known as Euler's method. Right now I'm busy, but I'll try to post more on this plus some nice links.
Here are some excellent links that should get you on your feet. YOU NEED TO REGISTER ON GAMASUTRA.COM WORTH IT FOR THIS ARTICLE!http://www.gamasutra.com/features/20000215/lander_01.htm Part 1 of heckers game physics, which includes Euler integration: Physics, Part 1: The Next Frontier: http://www.d6.com/users/checker/pdfs/gdmphys1.pdf Hecker's main page and his other two parts, including sample game physics applications: http://www.d6.com/users/checker/dynamics.htm In the rare case that you need any more explanation, just post!