Tutorial :obj-c linear interpolation between two numbers



Question:

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?


Solution:1

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;  }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »