views:

279

answers:

1

Just wondering if there are methods already implemented for handling linear interpolation between two numbers in foundation/something else that comes with Xcode? It's hardly an advanced thing to implement yourself, but I usually find myself reimplementing things that have already been implemented, and it's nice to use functionality that already exists (plus it's more standardized).

So what I'd like is something like this:

lerp(number1, number2, numberBetween0And1);

// Example:
lerp(0.0, 10.0, .5); // returns 5.0

Does it exist?

+3  A: 

No, but it's an easy one-liner:

inline double lerp(double a, double b, double t)
{
    return a + (b - a) * t;
}

inline float lerpf(float a, float b, float t)
{
    return a + (b - a) * t;
}
Adam Rosenfield