# Framerate independent nonlinear interpolation

## Recommended Posts

I can't find anything about this from Google, possibly because I don't know the mathematical name of what I'm trying to calculate. What I'm trying to do is convert a framerate dependent nonlinear interpolation algorithm into an equivalent framerate independent algorithm. What I have now is: newOffset = oldOffset / 2.0; If this executes at a different framerate, the object will move at a different speed, which is precisely what I don't want. How do I rewrite this equation to take into account either the time since the last frame or the current framerate (both of which are available to this function)?

##### Share on other sites
I don't think I understood everything you said there, but I do know how to transform that formula for a non-integer number of steps:

newOffset = oldOffset * pow(0.5, num_steps);

##### Share on other sites
Your lerp rate in this case is 0.5 per step. And you expect the steps to happen at a certain frequency. You should look for an equation that will modify the lerp rate based on the step frequency so that the result is as close to the original as possible. I'm pretty sure it's impossible, but there is a common formula which is close within a reasonable frame rate range.

##### Share on other sites
Let me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?

##### Share on other sites
Quote:
 Original post by DathgaleLet me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?

I just told you...

##### Share on other sites
In the case of x / 2 at 30ms, x / 4 at 60ms given a time of 40ms you would be (40-30)/(60 - 30)= 1/3 of the way there would be a linear interpolation. If you want a nonlinear interpolation you are going to have to be more specific there is more than one.

Linear interpolation will give you a constant velocity over the motion. if you want a more natural motion where things start moving slowly speed up and then slow down before stopping then you want spline interpolation in animation software(or blender at least) it is called an IPO curve.

##### Share on other sites
Yes, generally there are many ways of interpolating data, but he has a very particular case that lends itself very naturally to a continuous extension:

a(0) = x
a(n) = a(n-1)/2, if n>0

You can easily get the formula
a(n) = x * pow(0.5, n)

...and then you can evaluate it at any point in time.

##### Share on other sites
Quote:
Original post by alvaro
Quote:
 Original post by DathgaleLet me put this another way. If x is the position of an object at 0 milliseconds, and that object is at x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms, etc... then what is the position of that object at any arbitrary time?

I just told you...

You said you didn't understand all of my question before; just making sure a better understanding didn't change anything. Thanks for the help.

Stonemetal: x / 2 at 30ms, x / 4 at 60ms, x / 8 at 90ms

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982130

• 24
• 9
• 9
• 13
• 11