Skip to content

Commit f507c07

Browse files
Cubic interpolation
1 parent ec62993 commit f507c07

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

inmath/interpolate.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,14 @@ T hermite(T)(T x, T tx, T y, T ty, float t) {
151151
float h3 = t^^3 - 2 * t^^2 + t;
152152
float h4 = t^^3 - t^^2;
153153
return h1 * x + h3 * tx + h2 * y + h4 * ty;
154+
}
155+
156+
/// Cubic interpolation
157+
T cubic(T)(T p0, T p1, T p2, T p3, float t) {
158+
T a = -0.5 * p0 + 1.5 * p1 - 1.5 * p2 + 0.5 * p3;
159+
T b = p0 - 2.5 * p1 + 2 * p2 - 0.5 * p3;
160+
T c = -0.5 * p0 + 0.5 * p2;
161+
T d = p1;
162+
163+
return a * (t ^^ 3) + b * (t ^^ 2) + c * t + d;
154164
}

0 commit comments

Comments
 (0)