Skip to content

Commit

Permalink
Cubic interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Oct 23, 2022
1 parent ec62993 commit f507c07
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions inmath/interpolate.d
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,14 @@ T hermite(T)(T x, T tx, T y, T ty, float t) {
float h3 = t^^3 - 2 * t^^2 + t;
float h4 = t^^3 - t^^2;
return h1 * x + h3 * tx + h2 * y + h4 * ty;
}

/// Cubic interpolation
T cubic(T)(T p0, T p1, T p2, T p3, float t) {
T a = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3;
T b = p0 - 2.5 * p1 + 2 * p2 - 0.5 * p3;
T c = -0.5 * p0 + 0.5 * p2;
T d = p1;

return a * (t ^^ 3) + b * (t ^^ 2) + c * t + d;
}

0 comments on commit f507c07

Please sign in to comment.