integration techniques

26
Integration Techniques Marq Singer ([email protected])

Upload: lilli

Post on 10-Jan-2016

24 views

Category:

Documents


2 download

DESCRIPTION

Integration Techniques. Marq Singer ([email protected]). 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. The Problem. Physical simulation with force dependant on position or velocity - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Integration Techniques

Integration Techniques

Marq Singer ([email protected])

Page 2: Integration Techniques

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

Page 3: Integration Techniques

Essential Math for Games

The Problem

• Physical simulation with force dependant on position or velocity

• Start at x0, v0

• Only know:

Page 4: Integration Techniques

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

Page 5: Integration Techniques

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 x0, v0, time step h

Page 6: Integration Techniques

Essential Math for Games

Euler's Method

• Step across vector field of functions

• Not exact, but close

x0

x2

x1

x

t

Page 7: Integration Techniques

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

Page 8: Integration Techniques

Essential Math for Games

Euler’s Method (cont’d)

• Example of drift

x0

x1

x2

t

x

Page 9: Integration Techniques

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)

Page 10: Integration Techniques

Essential Math for Games

Midpoint Method

• Take two approximations

• Approximate at half the time step

• Use slope there for final approximation

h

h/2

x0.5

x0

x1

t

x

Page 11: Integration Techniques

Essential Math for Games

Midpoint Method

• Writing it out:

• Can still oscillate if h is too large

Page 12: Integration Techniques

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

Page 13: Integration Techniques

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

Page 14: Integration Techniques

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

Page 15: Integration Techniques

Essential Math for Games

Implicit Methods

• Result of backwards Euler

• Solution converges more slowly

• But it converges!

x0

x1

x2

t

x

Page 16: Integration Techniques

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)

Page 17: Integration Techniques

Essential Math for Games

Implicit Methods

• Example of predictor-corrector:

Page 18: Integration Techniques

Essential Math for Games

Implicit Methods

• Solving using linear system:

• Resulting matrix is sparse, easy to invert

Page 19: Integration Techniques

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

Page 20: Integration Techniques

Essential Math for Games

Verlet Integration

• Others: Leapfrog Verlet

Velocity Verlet

Page 21: Integration Techniques

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

Page 22: Integration Techniques

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

Page 23: Integration Techniques

Essential Math for Games

Multistep Methods (Cont’d)

• Adams-Bashforth 2-Step Method (explicit)

• Adams-Moulton 2-Step Method (implicit)

)()(32 11 iiii ffh

yyyy

)()(8)(512 111 iiiii fffh

yyyyy

Page 24: Integration Techniques

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

Page 25: Integration Techniques

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

Page 26: Integration Techniques

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.