integration techniques
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 PresentationTRANSCRIPT
Integration Techniques
Marq Singer ([email protected])
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
Essential Math for Games
The Problem
• Physical simulation with force dependant on position or velocity
• Start at x0, v0
• Only know:
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
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
Essential Math for Games
Euler's Method
• Step across vector field of functions
• Not exact, but close
x0
x2
x1
x
t
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
Essential Math for Games
Euler’s Method (cont’d)
• Example of drift
x0
x1
x2
t
x
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)
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
Essential Math for Games
Midpoint Method
• Writing it out:
• Can still oscillate if h is too large
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
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
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
Essential Math for Games
Implicit Methods
• Result of backwards Euler
• Solution converges more slowly
• But it converges!
x0
x1
x2
t
x
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)
Essential Math for Games
Implicit Methods
• Example of predictor-corrector:
Essential Math for Games
Implicit Methods
• Solving using linear system:
• Resulting matrix is sparse, easy to invert
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
Essential Math for Games
Verlet Integration
• Others: Leapfrog Verlet
Velocity Verlet
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
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
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
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
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
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.