# Logarithmic Interpolation

I am trying to come up with a method which does logarithmic and exponential interpolation.

We know that linear interpolation Mathf.Lerp as below uses from + t . (to-from)

``````float Lerp(float from, float to, float t);
``````

And ideal method I need would look like “Logerp(from, to, t, w)”

• A start value (from)
• An end value (to)
• A 0-1 range percentage to use for interpolation (t)
• And finally as an addition to the classical lerp parameters above, a 0-1 range parameter that defines the distribution weight of the values. So if it’s closer to 0, distribution will be logarithmic. If it’s closer to 1, it will be exponential. If it’s exactly 0.5, distribution will be linear. So basically it defines the curvature of the logarithmic graph. (w)

Can you write such a method or a mathematical representation of the described requirement?

I ended up using an AnimationCurve. I have a public field of type AnimationCurve with two keyframes at 0 and 1, which I can edit from the inspector too. When I want to get a specific value at a time I just use the below code.

``````return from + curve.Evaluate(t) * (to - from);
``````

If I wasn’t going to go with the AnimationCurve, I was going to use below two formulas for exponential and logarithmic curves respectively

``````from + (to - from) * Mathf.Pow(t, w);
to - (to - from) * Mathf.Log(t, w);
``````