Skip to content

Instantly share code, notes, and snippets.

@donkaban
Created July 11, 2014 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donkaban/662b23a33b6e62c4a20a to your computer and use it in GitHub Desktop.
Save donkaban/662b23a33b6e62c4a20a to your computer and use it in GitHub Desktop.
Interpolates
namespace interpolate
{
template<typename T> T linear(const T &v0,const T &v1,float t)
{
return v0 + (v1 - v0) * t;
}
template<typename T> T cosine(const T& v0, const T& v1, float t)
{
auto t2 = (1.0 - cos(t * PI)) / 2.0;
return v0 * (1.0 - t2) + v1 * t2;
}
template<typename T> T cubic(const T& a, const T& b, const T& c, const T& d, float t)
{
auto t2 = t * t;
auto a0 = d - c - a + b;
auto a1 = a - b - a0;
auto a2 = c - a;
auto a3 = b;
return(a0 * t * t2 + a1 * t2 + a2 * t + a3);
}
template<typename T> T bezier(const T& a, const T& b, const T& ak, const T& bk, float t)
{
auto t2 = (1.0 - t) * (1.0 - t);
auto t3 = (1.0 - t) * t2;
auto Ak = ak+a;
auto Bk = bk+b;
return t3 * a + 3 * t2 * t * Ak + 3*(1-t) * t * t * Bk + t*t*t*b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment