Download presentation

Presentation is loading. Please wait.

1
Integration Techniques Marq Singer (marq@essentialmath.com)

2
Essential Math for Games Integrators Solve “initial value problem” for ODEs Used Euler’s method in previous talk But not the only way to do it Are other, more stable ways

3
Essential Math for Games The Problem Physical simulation with force dependant on position or velocity Start at x 0, v 0 Only know:

4
Essential Math for Games The Solution Do an iterative solution Start at some initial value Ideally follow a step-by-step (or stepwise) approximation of the function

5
Essential Math for Games Euler’s Method (review) Idea: we have the slope ( x or v ) Follow slope to find next values of x or v Start with x 0, v 0, time step h

6
Essential Math for Games Euler's Method Step across vector field of functions Not exact, but close x0x0 x2x2 x1x1 x t

7
Essential Math for Games Euler’s Method (cont’d) Has problems Expects the slope at the current point is a good estimate of the slope on the interval Approximation can drift off the actual function – adds energy to system! Gets worse the farther we get from known initial value Especially bad when time step gets larger

8
Essential Math for Games Euler’s Method (cont’d) Example of drift x0x0 x1x1 x2x2 t x

9
Essential Math for Games Stiffness Running into classic problem of stiff equations Have terms with rapidly decaying values Larger decay = stiffer equation = need smaller h Often seen in equations with stiff springs (hence the name)

10
Essential Math for Games Midpoint Method Take two approximations Approximate at half the time step Use slope there for final approximation h h/2 x 0.5 x0x0 x1x1 t x

11
Essential Math for Games Midpoint Method Writing it out: Can still oscillate if h is too large

12
Essential Math for Games Runga-Kutta Use weighted average of slopes across interval How error-resistant indicates order Midpoint method is order two Usually use Runga-Kutta Order Four, or RK4

13
Essential Math for Games Runga-Kutta (cont’d) Better fit, good for larger time steps Expensive -- requires many evaluations If function is known and fixed (like in physical simulation) can reduce it to one big formula But for large timesteps, still have trouble with stiff equations

14
Essential Math for Games Implicit Methods Explicit Euler methods add energy Implicit Euler removes it Use new velocity, not current E.g. Backwards Euler: Better for stiff equations

15
Essential Math for Games Implicit Methods Result of backwards Euler Solution converges more slowly But it converges! x0x0 x1x1 x2x2 t x

16
Essential Math for Games Implicit Methods How to compute x' i+1 or v' i+1 ? Derive from formula (most accurate) Compute using explicit method and plug in value (predictor-corrector) Solve using linear system (slowest, most general)

17
Essential Math for Games Implicit Methods Example of predictor-corrector:

18
Essential Math for Games Implicit Methods Solving using linear system: Resulting matrix is sparse, easy to invert

19
Essential Math for Games Verlet Integration Velocity-less scheme From molecular dynamics Uses position from previous time step Stable, but not as accurate Good for particle systems, not rigid body

20
Essential Math for Games Verlet Integration Others: Leapfrog Verlet Velocity Verlet

21
Essential Math for Games Multistep Methods Previous methods used only values from the current time step Idea: approximation drifts more the further we get from initial value Use values from previous time steps to calculate next one Anchors approximation with more accurate data

22
Essential Math for Games Multistep Methods (cont’d) Two types of multistep methods Explicit method determined only from known values Implicit method formula includes value from next time step Use Runga-Kutta to calculate initial values, predictor-correct for implicit

23
Essential Math for Games Multistep Methods (Cont’d) Adams-Bashforth 2-Step Method (explicit) Adams-Moulton 2-Step Method (implicit)

24
Essential Math for Games Variable Step Size Idea: use one level of calculation to compute value, one at a higher level to check for error If error high, decrease step size Not really practical because step size can be dependant on frame rate Also expensive, not good for real-time

25
Essential Math for Games Which To Use? In practice, Midpoint or Euler’s method may be enough if time step is small At 60 fps, that’s probably the case Having trouble w/sim exploding? Try implicit Euler or Verlet

26
Essential Math for Games References Burden, Richard L. and J. Douglas Faires, Numerical Analysis, PWS Publishing Company, Boston, MA, 1993. Witken, Andrew, David Baraff, Michael Kass, SIGGRAPH Course Notes, Physically Based Modelling, SIGGRAPH 2002. Eberly, David, Game Physics, Morgan Kaufmann, 2003.

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google