Lecture IV: Time Discretization
Motivation Kinematics: continuous motion in continuous time Computer simulation: Discrete time steps t Discrete Space (mesh particles)
Updating Position Force induces acceleration. When mass is constant: F p, t = m a(p, t) Derivatives: v - t = a(t) and p - t = v(t) Thus: F p, t = m p -- (t) This is a differential equation Often difficult to analytically solve in real-time applications. Often a = a v, t dependence. Discretization: stability and convergence issues. 3
Taylor Approximation A function at t + t can be approximated by the function at t with derivatives: p t + t = p t + t p - t + t0 2 p-- t + + t3 n! p 3 t We do not usually use (or have) more than second derivatives. 4
First-Order Approximation If t is small enough, we approximate linearly: p 6 t + t p 6 t + t p 6 - t Euler s Method: approximating forward both velocity and position within the same step: v t + t = v t + a t t = v t + F(t) m t p 6 (t + t) = p 6 (t) + v(t) t Unknown for next time step Known for this time step 5
Euler s Method 5.1 This is known as Euler s method v t + t = v t + a t t p 6 (t + t) = p 6 (t) + v(t) t t v(t t) a(t t) v(t) t + t v(t) v(t + t) a(t) 6
Euler s Method Note: we approximate the velocity as constant between frames. We compute the acceleration of the object from the net force applied on it: F t a t = m We compute the velocity from the acceleration: v t + t = v t + a t t We compute the position from the velocity: p 6 t + t = p 6 t + v(t) t 7
Issues with Linear Dynamics A mere sequence of instants. Without the precise instant of bouncing. Trajectories are piecewiselinear. Constant velocity and acceleration in-between frames. 8
Time Step? When t 0, we converge to p 6 s v t dt. @ Reducing t as much as possible? First-order method, piecewise-constant velocity: not very stable. 9
Time Step First-order assumption: the slope at t as a good estimate for the slope over the entire interval t. The approximation can drift off the function. Farther drifting ó tangent approximation worse. x 0 x B errors x @ 10
Midpoint Method Estimating tangent in Half step: v t + t t = v t + a t, v 2 2 Full step: v t + t = v t + a t + C 0, v t + C 0 t Second-order approximation. 11
Midpoint Method Approximating the tangent in mid-interval. Applying it to initial point across the entire interval. Error order: the square of the time step O t 0. Better than Euler s method (O( t)) when t < 1. Approximating with a quadratic curve instead of a line. x B x B/0 can still drift off the function. x B x @ 12
Improved Euler s Method Considers the tangent lines to the solution curve at both ends of the interval. Velocity to the first point (Euler s prediction): v B = v t + t a(t, v) Velocity to the second point (correction point): v 0 = v t + t a t + t, v B Improved Euler s velocity v t + t = v B + v 0 2 Compute position similarly with v B, v 0 instead of a. 13
Improved Euler s Method The order of the error is O( t 0 ). The final derivative is still inaccurate. v 0 v t + t = v B + v 0 2 v(t) v B t 14
Runge-Kutta Method There are methods that provide better than quadratic error. The Runge-Kutta order-four method (RK4) is O( t I ). A combination of the midpoint and modified Euler s methods, with higher weights to the midpoint tangents than to the endpoints tangents. 15
RK4 Computing the four following tangents (note dependence of acceleration on velocity): v B = t a(t, v(t)) v 0 = t a t + t 2, v t + 1 2 v B v J = t a t + t 2, v t + 1 2 v 0 v I = t a t + t, v t + v J Blend as follows: v t + t = v t + v B + 2v 0 + 2v J + v I 6 Compute position similarly with v values. 16
RK4 5.2 v B = t a(t, v(t)) v 0 = t a t + t 2, v t + 1 2 v B v J = t a t + t 2, v t + 1 2 v 0 v I = t a t + t, v t + v J v 0 v t + t v J v B + 2v 0 + 2v J + v I 6 v B v I v(t) t/2 t/2 17
Based on the Taylor expansion series of the previous time step and the next one: p 6 t + t + p 6 t t Verlet integration = p 6 t + t p 6 - t + t0 2 p 6 -- t + + p 6 t t p 6 - t + t0 2 p 6 -- t 18
Verlet integration Approximating without velocity: p 6 t + t = 2p 6 t p 6 t t + t 0 p 6 -- t +O( t I ) p 6 (t + t) p 6 (t t) p 6 (t) t 0 a t 2 p 6 (t) p 6 (t t) t t 19
An O( t 0 ) order of error. Verlet integration Very stable and fast without the need to estimate velocities. We need an estimation of the first p 6 (t t) Usually obtained from one step of Euler s or RK4 method. Difficult to manage velocity related forces such as drag or collision. 20
Implicit methods So far: computing current position p 6 (t) and velocity v(t) for the next position (forward). Those are denoted as explicit methods. In implicit methods, we make use of the quantities from the next time step! p 6 t = p 6 t + t t v(t + t) this particular one is called backward Euler. the goal: finding position p 6 t + t which produces p 6 if running the simulation backwards. 21
Implicit methods Not more accurate than explicit methods, but more stable. x @ x B Especially for a damping of the position (e.g. drag force or kinetic friction). x 0 22
Backward Euler How to compute the velocity at a position in the future? Given the forces applied, extracting from the formula: Example: a drag force F L = b v is applied: v t + t = v t t b v(t + t) And therefore v t + t = v(t) 1 + t b 23
Backward Euler Often not knowing the forces in advance (likely case in a game). Or that the backward equation is not easy to solve. We use a predictor-corrector method: one step of explicit Euler s method use the predicted position to calculate v(t + t) More accurate than explicit method but twice the amount of computation. 24
Semi-Implicit Method Combines the simplicity of explicit Euler and stability of implicit Euler. Runs an explicit Euler step for velocity and then an implicit Euler step for position: v t + t = v t + t a t = v t + t F(t)/m p t + t = p(t) + t v t = p(t) + t v(t + t) t v(t) a(t) v(t + t) t + t 25
Semi-Implicit Method The position update in the second step uses the next velocity in the implicit scheme. Good for position-dependent forces. Conserves energy over time, and thus stable. Not as accurate as RK4 (order of error is still O( t)), but cheaper and yet stable. Very popular choice for game physics engine. 26
First-order methods Implicit and Explicit Euler method, Semi-implicit Euler, Exponential Euler Second-order methods Verlet integration, Velocity Verlet, Trapezoidal rule, Beeman s algorithm, Midpoint method, Improved Euler s method, Heun s method, Newmark-beta method, Leapfrog integration. Higher-order methods Summary Runge-Kutta family methods, Linear multistep method. 27
Dimension Concluding remarks Integration methods shown for 1D variables. Generalization using vector based structures (e.g., Jacobians). Rotational motion The integration methods work exactly the same for angular displacement θ, velocity ω and acceleration α. Evaluation of all dimensions and variables should be done for the same simulation time t. 28