# Interpolation: The art of predicting things in the wrong place

So I spent the morning buggering around with springs and trying to balance them under various forces. Complex but interesting.

Went for a run. Not so interesting, it rained.

Then came back and worked on an interesting problem. If you have a process that needs to run quickly or at a high frequency and another process that requires that data result at a lower frequency then you have a bit of an issue. You have to bridge the data between the two processes. It’s all down to time stamps. So your high frequency process you store two lots of data results, the current time stamp and whatever was stored previous. You then just flip between updating these two lots of data. Basically you end up with two lots of data both with different time stamps. Then on your low frequency process you take the current time step. Now the fun bit. You take the biggest time stored and subtract the smallest time. This gives you the time interval between the two lots of data. You then subtract the smallest time stamp from the time stamp you want. You then divide the wanted time interval by the stored time interval. This then gives you the linear interpolation value. The art being to subtract the later data from the earlier data then multiply by the interpolation value then add the earlier data again. So what you are trying to do is generate a value of the data exactly between those two stored values. This usually works fine if the time stamp you want is between them. If it’s before or after then you need a crystal ball. You are taking the difference between data and then trying to predict the future. It’s an interesting task, but if you keep the update frequency high enough the results are pretty accurate. Incidentally, linear interpolation is usually fine. Rotation on the other hand is somewhat more tricky, you have two matrices, ignore the translation part that’s just linear. You need to convert the matrix to a quaternion. Once you have a pair of quaternions you can perform a thing called a ‘slerp’, which is a bit like a rotational ‘lerp’. Again, it can produce good results. Tomorrow I will try and predict the weekends lottery numbers using linear interpolation.

Did some more Japanese. Almost at the end of unit 6 now.