Saturday, August 13, 2005

Smooth Interpolation

It is often useful when interpolating to accelerate into the interpolation and/or decelerate out of the interpolation. For example, an object moving from one place to another looks a little better if it accelerates from its stationary state into the move, and then slows down before stopping again. Here I'll talk about how to smooth out a linear interpolation as much (or as little) as you want.

Without any smoothing, you just linearly increase the interpolation factor from zero to one. Instead of this linear movement, let's try increasing the interpolation factor as a function of time f(t). Now let's say that the length in time of the interpolation is 1 (you can easily scale this to any interpolation over any time length), and that the length of the acceleration is a, and the length of the deceleration is b. Then we want the derivative of f(t) to look something like this

derivative

Now we just need to determine the height of this trapezoid, such that the area under f'(t) is 1 so that f(1) = 1. The area under the curve is

img1

So for the acceleration (0 ≤ t < a)

img2

And for the linear part (a ≤ t < 1-b)

img3

Our initial condition for this part is that f is continuous at f(a), so

img4

So the linear segment is

img5

And finally, for the deceleration (1-b ≤ t ≤ 1) we have

img6

Again, to satisfy continuity at f(1-b), we need

img7

So the deceleration segment is

img8

And the function with the desired acceleration and deceleration is

img9

Here is a graph of f(t) for various values of a and b.

function

2 comments:

  1. data_smith@hotmail.com4/14/09, 10:32 AM

    Seriously i love your blog!

    I mean as an indie game developer and a math-lover.. seriously! MOAR!

    ReplyDelete