1 / 46

Numerical Integration

Numerical Integration. Erin Catto Blizzard Entertainment. Basic Idea. Games use differential equations for physics. These equations are hard to solve exactly. We can use numerical integration to solve them approximately. Overview. Differential Equations Numerical Integrators Demos.

pferreira
Download Presentation

Numerical Integration

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Numerical Integration Erin CattoBlizzard Entertainment

  2. Basic Idea • Games use differential equations for physics. • These equations are hard to solve exactly. • We can use numerical integration to solve them approximately.

  3. Overview • Differential Equations • Numerical Integrators • Demos

  4. Typical Game Loop Start t = 0 Choose Dt Player Input t = t + Dt Simulate Dt Render

  5. Simulation • Animation • AI • Physics • Differential Equations

  6. What is a differential equation? • An equation involving derivatives. rate of change of a variable = a function

  7. Anatomy of Differential Equations • State • Dependent variables • Independent variables • Initial Conditions • Model • The differential equation itself

  8. Projectile Motion • State • Independent variable: time (t) • Dependent variables: position (y) and velocity (v) • Initial Conditions • t0, y0, v0

  9. Projectile Motion • Model: vertical motion y x

  10. First Order Form • Numerical integrators need differential equations to be put into a special format.

  11. First Order Form • Arrays of equations work too.

  12. Projectile MotionFirst Order Form y x

  13. Projectile MotionFirst Order Form y x

  14. Mass-Spring Motion • Consider the vertical motion of a character.

  15. Mass-Spring Motion • State • time: t • position: x • velocity: v • Initial Conditions • t0, x0, v0 x

  16. Mass-Spring Motion • Idealized model m x k ground

  17. Mass-Spring Motion • First Order Form

  18. Solving Differential Equations • Sometimes we can solve our DE exactly. • Many times our DE is too complicated to be solved exactly.

  19. Hard Problems • Nonlinear equations • Multiple variables

  20. Hard Problems • Projectile with air resistance

  21. Hard Problems • Mass-spring in 3D

  22. Hard Problems • Numerical integration can help! • Handles nonlinearities • Handles multiple variables

  23. Numerical Integration • Start with our first order form

  24. t t+h A Simple Idea • Approximate the slope. x t

  25. A Simple Idea • Forward difference:

  26. A Simple Idea • Shuffle terms:

  27. A Simple Idea • Using this formula, we can make a time step h to find the new state. • We can continue making time steps as long as we want. • The time step is usually small

  28. Explicit Euler • This is called the Explicit Euler method. • All terms on the right-hand side are known. • Substitute in the known values and compute the new state.

  29. What If … • This is called the Implicit Euler method. • The function depends on the new state. • But we don’t know the new state!

  30. Implicit Euler • We have to solve for the new state. • We may have to solve a nonlinear equation. • Can be solved using Newton-Raphson. • Usually impractical for games.

  31. Implicit vs Explicit • Explicit is fast. • Implicit is slow. • Implicit is more stable than explicit. • More on this later.

  32. Opening the Black Box • Explicit and Implicit Euler don’t know about position or velocity. • Some numerical integrators work with position and velocity to gain some advantages.

  33. The Position ODE • This equation is trivially linear in velocity. • We can exploit this to our advantage.

  34. Symplectic Euler • First compute the new velocity. • Then compute the new position using the new velocity.

  35. Symplectic Euler • We get improved stability over Explicit Euler, without added cost. • But not as stable as Implicit Euler

  36. Verlet • Assume forces only depend on position. • We can eliminate velocity from Symplectic Euler.

  37. Verlet • Write two position formulas and one velocity formula.

  38. Verlet • Eliminate velocity to get:

  39. Newton • Assume constant force: • Exact for projectiles (parabolic motion).

  40. Demos • Projectile Motion • Mass-Spring Motion

  41. Integrator Quality • Stability • Performance • Accuracy

  42. Stability • Extrapolation • Interpolation • Mixed • Energy

  43. Performance • Derivative evaluations • Matrix Inversion • Nonlinear equations • Step-size limitation

  44. Accuracy • Accuracy is measured using the Taylor Series.

  45. Accuracy • First-order accuracy is usually sufficient for games. • You can safely ignore RK4, BDF, Midpoint, Predictor-Corrector, etc. • Accuracy != Stability

  46. Further Reading &Sample Code • http://www.gphysics.com/downloads/ • Hairer, Geometric Numerical Integration

More Related