What is this interpolation function called?

Started by
7 comments, last by Josh Klint 1 year, 6 months ago

This function interpolates between two values with a fixed speed. The nice thing about it is you can use it over several frames without keeping track of the starting position and the rate of change stays constant.

What is the common name for this function? It's not mix/lerp. I can't be the first person to think of this:

float X(const float start, const float stop, const float amount)
{
	if (Abs(stop - start) < amount) return stop;
	if (stop > start) return start + amount;
	return start - amount;
}

10x Faster Performance for VR: www.ultraengine.com

Advertisement

Looks like linear interpolation to me. “amount” is just the step size of the linear interpolation. It's common to do something similar to this when interpolating audio gains.

I'm not sure that's really interpolation at all. It seems like you are just taking some value, offsetting it by a second value and clamping the result to a distance from the initial value. I can see that being the last part of an interpolation process. But we don't get to see how the value was generated.

MoveTowards()?

Aressera said:
Looks like linear interpolation to me. “amount” is just the step size of the linear interpolation. It's common to do something similar to this when interpolating audio gains.

Isn't linear interpolation more akin to (a, b, alpha), where alpha is between 0.0 and 1.0 and, well, linearily interpolates between a and b when moving from 0.0=>1.0?

This function seems more like “MoveTowards” that you can see in Unity https://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.html; though I'm not sure what the mathematically correct term is. Also “start” for the first parameter is a bit misleading, at least it confused me. I guess its technically correct, but I find “current” for the Unity-function a lot more clear, as it indicates that this value is being (most likely) updated as a result of the call.

Juliean said:
Isn't linear interpolation more akin to (a, b, alpha), where alpha is between 0.0 and 1.0 and, well, linearily interpolates between a and b when moving from 0.0=>1.0?

That's the canonical form, but you can also imagine interpolating from A to B in N steps. In that case, the step size is (B-A)/N. On each step, that step size is added to the current value until it reaches B. The current value will linearly approach B. A similar effect could be achieved by setting alpha = 1/N, 2/N, 3/N etc in the traditional form, it's mathematically equivalent.

Aressera said:
That's the canonical form, but you can also imagine interpolating from A to B in N steps. In that case, the step size is (B-A)/N. On each step, that step size is added to the current value until it reaches B. The current value will linearly approach B. A similar effect could be achieved by setting alpha = 1/N, 2/N, 3/N etc in the traditional form, it's mathematically equivalent.

Sure, I guess both qualify as “linear interpolation”. What I was thinking about was a function that is called “lerp”, which I would expect to have the form I mentioned.

Juliean said:

This function seems more like “MoveTowards” that you can see in Unity https://docs.unity3d.com/ScriptReference/Mathf.MoveTowards.html; though I'm not sure what the mathematically correct term is. Also “start” for the first parameter is a bit misleading, at least it confused me. I guess its technically correct, but I find “current” for the Unity-function a lot more clear, as it indicates that this value is being (most likely) updated as a result of the call.

Strange name, but in the absence of any other common name I will go with this.

10x Faster Performance for VR: www.ultraengine.com

This topic is closed to new replies.

Advertisement