Game Development Reference
In-Depth Information
Clearly, a better way is needed to estimate the value of z n+1 , and that's where the fourth-
order Runge-Kutta method comes into the picture. The essence of the fourth-order Runge-Kutta
scheme is that a series of estimates are made for the z-location at the new time by evaluating
the velocity at different values of x and t . An initial estimate is made for z n+1 using the velocity
at x n and t n (that is, Euler's method). A second estimate is computed by evaluating the velocity at a
point halfway between the known conditions and the results of the first estimate. Two more
estimates are made in a similar manner, and the final value for z n+1 is obtained from a linear
combination of the four estimates. The five mathematical equations that form the fourth-order
Runge-Kutta scheme when it is applied to solve Equation (4.19) are shown in Equation (4.23).
Δ=
zvzt
(,)
nn
Δ
t
(4.23a)
1
1
1
Δ=
zvz
(
zt
,
+ΔΔ
t
)
t
(4.23b)
2
n
1
n
2
2
1
1
Δ=
zvz
(
zt
,
+ΔΔ
t
)
t
(4.23c)
3
n
2
n
2
2
Δ
zvz zt
=
(
,
+Δ Δ
t
)
t
(4.23d)
4
n
3
n
ΔΔ
z
z
Δ
z
Δ
z
z
=+ +
z
1
2
+
3
+
4
(4.23e)
n
+
1
n
6336
Naturally, the Runge-Kutta method is not restricted to solving the ODE shown in
Equation (4.19). It can be applied to solve any first-order ODE. As long as a derivative can be
expressed as a function of the dependent and independent variables, the Runge-Kutta method
can be used to solve for the value of the dependent variable.
This section has provided a very brief introduction to Runge-Kutta ODE solution techniques.
If the theory behind Runge-Kutta solvers is still a bit unclear to you, don't worry. A little later in
this chapter, we will develop a Runge-Kutta code that you can use in your game programming.
Solving Higher-Order ODEs
As was mentioned before, the Runge-Kutta technique is designed for solving first-order ODEs.
So what do you do to solve higher-order ODEs? The answer is to expand the higher-order deriv-
atives into a series of first-order ODEs. The Runge-Kutta solver is then applied to each first-order
ODE. For example, let's say we want to model the motion of a spring. The location of a mass, m ,
at the end of a spring as a function of time is described by a second-order differential equation.
dx
2
dx
m
μ ++=
kx
0
(4.24)
2
dt
dt
In Equation (4.24), k is the spring constant that defines how stiff the spring is, and m is the
damping coefficient that characterizes how quickly the spring motion will die out. Knowing
that v x = dx/dt , the equation of motion for a spring shown in Equation (4.24) can be rewritten
as two first-order differential equations.
Search WWH ::




Custom Search