Game Development Reference
In-Depth Information
Fortunately, a number of techniques can be used to solve differential equations when a
closed-form solution is not possible. In the next section, a program called a Runge-Kutta ODE
solver will be presented that you can use to solve the differential equations that you will
encounter in your game programming. The Runge-Kutta ODE solver is versatile, dependable,
and applicable to a wide range of problems.
Fourth-Order Runge-Kutta ODE Solver
Many techniques have been developed over the years for solving ordinary differential equations.
The one presented in this chapter and used throughout this topic is called the fourth-order
Runge-Kutta method . This method is one of a family of step-wise integration methods, meaning
that from a set of initial conditions, the ODE is solved at discrete increments of the independent
variable. For the equations of motion, the independent variable will be time. The fourth-order
Runge-Kutta method is not the most efficient ODE solver available, but it is simple and depend-
able, and will give good results as long as very high accuracy is not required.
Tidbit Carl Runge and Martin Kutta were German mathematicians who, among other things, developed
methods to solve ordinary differential equations. The Runge-Kutta method, first presented in 1901, has really
stood the test of time. Despite the fact that they are over 100 years old, Runge-Kutta methods are still widely
used today.
Runge-Kutta methods are designed to work on first-order ODEs. If you recall from Chapter 1,
a first-order ODE is an equation with one dependent variable where the highest-order derivative
appearing in the equation is a first derivative. For example, an equation relating the derivative
of z-location with respect to time to the z-component of velocity would be a first-order ODE.
dz
()
dt =
vzt
,
(4.19)
z
The z-component of velocity, v z , in Equation (4.19) does not have to be a constant, but
instead is expressed as a general function of z and t . For example, consider the curve shown in
Figure 4-3 that displays z-location as a function of time. The shape of the curve indicates that
the z-location is a nonlinear function of time. The slope of the curve at any time, t , is equal to
the velocity, v z ( z,t ).
Let's say that the z-location and velocity, z n and v zn , are known at a given time, t n . We want
to determine the z-location at a future time, t n +Dt , where Dt is a certain time increment. For
small enough increments in the independent variable, t , the derivative in Equation (4.19) can
be replaced with its delta form.
dz
≈=
Δ
z
()
vzt
,
(4.20)
z
dt
t
The value of the z-location, z n+1 , at the future time t n +Dt can be determined from
Equation (4.20).
()
Δ=
zz
− =
z vzt
,
Δ
t
(4.21)
n
+
1
n
z
Search WWH ::




Custom Search