Can someone help explain interpolation?

Started by
3 comments, last by MERKB7661 12 years, 10 months ago
I have seen some references in coding books and forum posts to interpolation coding. What exactly is interpolation, and how does it apply to programming?
Advertisement
Imagine you want to plot a line, whose endpoints are of two different colours. As you draw the line, you vary one colour to the other colour. That's an example of interpolation.

Interpolation is a very useful technique for "filling in the blanks" between points of data.

More info here:
https://secure.wikimedia.org/wikipedia/en/wiki/Interpolation
Latest project: Sideways Racing on the iPad

I have seen some references in coding books and forum posts to interpolation coding. What exactly is interpolation, and how does it apply to programming?


It is a way of moving smoothly between two points.


Example:
Your model starts in a square, and wants to slide to another square. The slide should take 3 seconds. You are currently at 1.21 seconds, so you interpolate to find the current location.

In that case you divide how far along you are from the total time (1.21 / 3.0 = 0.40333) so you are about 40% of the way through, then you figure out the point that is 0.40333 of the way through the animation. You have just interpolated your location between two points.

I have seen some references in coding books and forum posts to interpolation coding. What exactly is interpolation, and how does it apply to programming?


More generally, interpolation is guessing about an unknown data point by analyzing information around it.


For example,
* If you know that on Sunday you had a full tank of gas and on Friday you were almost empty, you can use interpolation to guess that on Tuesday you had about half a tank.
* Or, if a plane took off from California at 7AM and reached New York at 1PM, you can use interpolation to guess that 10AM you might have been over Kansas.

There's another term called extrapolation. Extrapolation is guessing about an unknown data point by analyzing a trend leading up to that point. To use the same examples:
* If you know that on Sunday you had a full tank of gas and on Tuesday you had about half a tank, you can use extrapolation to guess that you'll be empty by Friday.
* Or, if a plane takes off from California at 7AM and makes it to Kansas by 10AM, you can use extrapolation to guess that you'll reach New York by 1PM.

Interpolation is used for lots of things in games. Animation is a big one. Animation is usually specified with keyframes. So an animation of a man raising his hand might involve 3 keyframes. The first has his hand by his side, the second keyframe has his hand a bit higher up, and the last one has his hand completely raised. Three frames would make for a rather jerky animation, so you might use interpolation to make it smooth. You can figure out the position of his hand at as fine a time-step as you want by analyzing the keyframes around that time. If you show the animation over 100 frames, the man's hand will move a tiny amount each frame, and the position of the hand in all but the initial three frames will be calculated by you using interpolation.
Thank you, thank you, and thank you!

This topic is closed to new replies.

Advertisement