Search code examples
c++cmathinterpolationeasing

Interpolating a value between two values


I'm looking for a function that interpolates a value between two values following a soft curve.

Here's an example:

enter image description here

float xLerp(float mMin, float mMax, float mFactor) { ... }

mFactor should be between 1 and 0.

How can I create a function similar to the one I drew?


Solution

  • As I said in comment, exponent fits quite well:

    double mBase = 5; // higher = more "curvy"
    double minY = pow(mBase, mMin - mBase);
    double maxY = pow(mBase, mMax - mBase);
    double scale = (mMax - mMin) / (maxY - minY);
    double shift = mMin - minY;
    return pow(mBase, mFactor - mBase) * scale + shift;
    

    Ugh, slope is all wrong, ugly hack...