Numerical Integration Jim Van Verth Insomniac Games [email protected].

63

Transcript of Numerical Integration Jim Van Verth Insomniac Games [email protected].

Page 1: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.
Page 2: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Numerical Integration

Jim Van VerthInsomniac Games

[email protected]

Page 3: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Talk Summary

Going to talk about: Euler’s method subject to errors Implicit methods help, but complicated Verlet methods help, but velocity out of step Symplectic methods can be good for both

Page 4: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Our Test Case

Page 5: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Our Test Case

Page 6: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Our Test Case

xt =?

x0

Page 7: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Constant velocity

v

xt =?

x0

Page 8: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Constant velocity

v

xt = x0+vt

x0

Page 9: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Constant accelerationv0

x0

xt = ?

a

Page 10: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Constant accelerationv0

x0

xt = ?

a

Page 11: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Constant accelerationv0

x0

xt = x0 + v0t + 1/2at2

a

Page 12: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Variable acceleration

x0

xt = ?

Page 13: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

Page 14: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1

Page 15: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1

v0a

Page 16: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1

v0a

v1

Page 17: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

Page 18: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

x2

Page 19: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

a

v1

x2

Page 20: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

a

v1

v2

x2

Page 21: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

v2

x2

Page 22: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

v0

x1v1

v2

x2

x i+1 = x i + viΔt

vi+1 = vi +a iΔt

Page 23: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0v0

a0

Page 24: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x1

x0v0

a0

Page 25: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0x1a0

v0v0

Page 26: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

v1 x0x1

v0v0

a0

Page 27: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0x1

v0

v1

Page 28: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x2

v2

x0x1

v0

v1

Page 29: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler’s method

x0

x1v1

v0

Page 30: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Euler

Okay for non-oscillating systems Explodes with oscillating systems Adds energy! Very bad!

Page 31: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta methods

x0

v0

Page 32: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta methods

x0

v0

v0.5

Page 33: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta methods

x0

v0.5

Page 34: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta methods

x0

v0.5

x1

Page 35: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta methods

x0

v0

Page 36: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Runge-Kutta 4

Very stable and accurate Conserves energy well But expensive: four evaluations of derivative

Page 37: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

Page 38: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x1

Page 39: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x1v1

Page 40: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

v1

Page 41: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x1

v1

Page 42: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x i+1 = x i + vi+1Δt

vi+1 = vi +a i+1Δt

x1

v1

Page 43: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x i+1 = x i + vi+1Δt

vi+1 = vi +a i+1Δt

x1v1

Page 44: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Implicit methods

x0v0

x i+1 = x i + vi+1Δt

vi+1 = vi +a i+1Δt

x1

v1

Page 45: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Backward Euler

Not easy to get implicit values More expensive than Euler

But tends to converge: better but not ideal

Page 46: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

x0 x-1

Page 47: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

x0 x-1

Page 48: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

x0at2 x-1

Page 49: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

x0

x1

x-1at2

Page 50: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

x i+1 = 2x i − x i−1 +aΔt 2

x0

x1

x-1at2

Page 51: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

Leapfrog Verlet

Velocity Verlet

vi+1/ 2 = vi−1/ 2 +a iΔt

x i+1 = x i + vi+1/ 2Δt

vi+1/ 2 = vi +a iΔt /2

x i+1 = x i + vi+1/ 2Δt

vi+1 = vi+1/ 2 +a i+1Δt /2

Page 52: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Verlet

Very stable Cheap

Not too bad, but have estimated velocity

Page 53: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

x0v0

a0

Page 54: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

x0v0

v1

v0

a0

Page 55: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

x0

v1

Page 56: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

vi+1 = vi +a iΔt

x i+1 = x i + vi+1Δt

x0

v1

Page 57: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

vi+1 = vi +a iΔt

x i+1 = x i + vi+1Δt

Page 58: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

Cheap and stable!

Not as accurate as RK4

Page 59: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Symplectic Euler

Cheap and stable!

Not as accurate as RK4 - but hey, it’s a game

Page 60: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Demo Time

Page 61: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

Which To Use? With simple forces, standard Euler might be okay But constraints, springs, etc. require stability Recommendation: Symplectic Euler

Generally stable Simple to compute (just swap velocity and position terms)

More complex integrators available if you need them -- see references

Page 62: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

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.

Page 63: Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com.

References

Hairer, et al, “Geometric Numerical Integration Illustrated by the Störmer/Verlet method,” Acta Numerica (2003), pp 1-51.

Robert Bridson, Notes from CPSC 533d: Animation Physics, University of BC.