Jump to content
  • Advertisement
Sign in to follow this  
DingOunan

Why I need the numerical integrator?

This topic is 3552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If given the velocity and the acceleration,I can immediately get Distance=1/2 a t^2 + v t what is the numerical integrator used for?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by DingOunan
If given the velocity and the acceleration,I can immediately get
Distance=1/2 a t^2 + v t
But what happens if the acceleration is constantly varying (i.e. the player is changing direction or speed)? You could get down and dirty with a bunch of calculus, but that could be very complicated (especially if acceleration is not controlled by a known function). Numerical integration is a very simple approach which approximates the (arbitrarily complicated) calculus required for this task.

Share this post


Link to post
Share on other sites
Thank you very much for the quick reply.
but,I think about another reason.
because the newtonian dynamic equation contains not only the external forces(applied by user),but also the constraining forces(like the force that attach the mass in a pendulum system)
the constraining force is difficult to calculate,so we use the lagrange dynamic equation,which is not easy to be integrated symboly.then we need the numerical integrator.

Am I right?

Share this post


Link to post
Share on other sites
Quote:
Original post by DingOunan
because the newtonian dynamic equation contains not only the external forces(applied by user),but also the constraining forces(like the force that attach the mass in a pendulum system) the constraining force is difficult to calculate,so we use the lagrange dynamic equation,which is not easy to be integrated symboly.then we need the numerical integrator.
You are correct, numerical integration can be used anytime we need to approximate a difficult integral.

Share this post


Link to post
Share on other sites
As an addendum to what swiftcoder said, numerical integration is sometimes necessary because we don't actually know what function is being integrated.

If we're updating the character's position, for example, and the player can apply forces to the character with the keyboard, we can't predict what forces the player will choose to apply. Therefore, we don't know how the acceleration of the character will change with time except at the present moment and any moments in the past where we chose to remember the state of the system.

Share this post


Link to post
Share on other sites
Another reason to use numerical integration is that many functions don't have primitives that can be expressed in closed formulas in terms of well-known functions, so analytical integration is not possible.

Share this post


Link to post
Share on other sites
I like the question. ;-)

The reasons people use numerical integration are that (1) it's easier than solving ODEs, and we are lazy (or would rather do other things), (2) accuracy doesn't matter much in games; it just has to 'look right,' and (3) since we need to know the value of the state every [small timestep] anyway, numerical integration can actually be faster than evaluating a complicated expression (the analytic solution to the differential equation) at all of those points.

But let me play devil's advocate for a second. I would assert that game physics, between collisions, can be evaluated symbolically in most cases. Because most of the time, what are you doing? Rigid body dynamics with collisions, and nothing more. (How often do you see lots of constraint forces in games, besides those that arise from collisions?) And what's more, evaluating the analytic solution to these differential equations is very cheap, so argument (3) above doesn't actually work.

I also disagree with the "unpredictable player input" argument, nilkn (Sorry!). But you see, over any time interval, the player is either hitting a key, or not hitting a key. The way you will probably interpret this -- if you say that keystrokes equate to forces (which I admit they usually don't; usually we just use kinematic models. But those are even simpler) is that over any time interval, the force exerted by the player is a constant. And we know the solution to the ODEs when the input is a constant!!

The only complication comes from handling collisions, but really the way that you do this won't be much different whether you're using analytic solutions or numerical integration. In fact, it might be faster when you use the analytic solution, because whereas when you use numerical integration, often what I've seen people do is use binary search to accurately determine the moment of collision, if you have the analytic solution then you have access to all the derivatives of your state trajectory and can use something that converges faster than binary search, like Newton-Raphson.

Plus, doing things this way will be more accurate, and avoid different-integrator-timestep issues, such as those that plagued Quake3 (players with different framerates could jump different heights. Naturally, you can also solve this problem with a constant physics rate, but this has its own problems).

Share this post


Link to post
Share on other sites
Emergent: I think your argument breaks down if you introduce some sort of drag, especially if you have random wind.

Share this post


Link to post
Share on other sites
Quote:
Original post by alvaro
Emergent: I think your argument breaks down if you introduce some sort of drag, especially if you have random wind.


True -- if the drag in nonlinear (say, quadratic); otherwise it can be solved easily. Random wind also isn't necessarily a problem (if the ODE is linear), since you end up with a stochastic differential equation, which you can again solve.

But I see where you're going, and I think you're right: The real argument, I suppose, is that numerical integration is more flexible. If I have linear drag and then want to switch to a quadratic drag, I can, easily, if I'm using numerical integration. Whereas if I'm using analytic solutions then everything breaks -- I simply can't (since an analytic solution doesn't exist).

Perhaps the "perfect" way to deal with these things is to abstract away the dynamics, so that to the rest of the code -- collision detection, etc -- it doesn't matter whether what's going on under the hood is numerical integration or the evaluation of analytic expressions (I know this partially contradicts what I said before about Newton-Raphson vs. binary search, but in truth, if you really want to, you can get derivatives out of your numerical integrator). But if you're not going to do that abstraction, then numerical integration is more flexible.

Share this post


Link to post
Share on other sites
Quote:
Original post by Emergent
But you see, over any time interval, the player is either hitting a key, or not hitting a key. The way you will probably interpret this -- if you say that keystrokes equate to forces (which I admit they usually don't; usually we just use kinematic models. But those are even simpler) is that over any time interval, the force exerted by the player is a constant. And we know the solution to the ODEs when the input is a constant!!


The point I was trying to make is that the ODE you're talking about is itself an approximation that is only valid locally (i.e., it's only valid for that specified time interval where you know exactly which keys are pressed).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!