Interpolation
From DmWiki
Interpolation is the process of making a value vary smoothly between two endpoints or extremes. For instance, if you want to move a camera from point A to point B, you typically don't let it instantly "warp" from one to the other, but let it smoothly move across the space in between over a small amount of time. Providing the smooth "in-between" values in situations like this is the job of interpolation.
There are many kinds of interpolation available, depending on the kind of motion desired. For example,
- Linear interpolation
- Cubic interpolation
- Spherical interpolation
Most interpolation methods can be extended to as many dimensions as necessary; for example, linear interpolation becomes bilinear in two dimensions, or trilinear in three dimensions.
Linear interpolation
Linear interpolation is used a lot in game programming since it's simple, fast to write and can be used to animate lot of different parameters in an easy manner.
Changing the value of the t parameter in the range [0.0, 1.0] is it possible to see that you can obtain all the values from vbegin to vend.
- When t = 0.0 you have vinterpolated = vbegin + 0
- When t = 1.0 you have vinterpolated = vbegin + vend - vbegin that is simply vinterpolated = vend
With linear interpolation you can quickly animate any parameter of your game, from 2D sprites to 3D objects, from layers of textures to color fades in a menu screen. To change a little interpolation the t parameter can be changed, placing a different formula (bearing in mind that the function result has to be in the [0.0, 1.0] range) such as t2 or others.
Spherical interpolation
Spherical interpolation between two vectors does not interpolate each coordinate individually like linear interpolation does. Instead, the direction and lengths are interpolated individually, like demonstrated on the image below.
The spherical interpolation of two normalized vectors is calculated using the formula:
This can be coded like this:
Vec3 NormalizedSphericalInterpolation(Vec3 a, Vec3 b, float t)
{
float x = acos( a.Dot(b) );
return ( sin((1-t) * x) * a + sin(t* x) * b ) / sin(x);
}
For non-normalized vectors, the length must first be calculated, then interpolated:
Vec3 SphericalInterpolation(Vec3 a, Vec3 b, float t)
{
float lenA = a.GetLength();
float lenB = b.GetLength();
Vec3 dir = NormalizedSphericalInterpolation( a / lenA, b / lenB, t );
return dir * ( lenA + t * (lenB - lenA) );
}
This article is a stub. You can help improve the article by expanding it.

