UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

27 lines (22 loc) 782 B
/** * Perform cubic Hermite interpolation * @see https://en.wikipedia.org/wiki/Cubic_Hermite_spline * @param {number} t normalized interpolation position in interval [0,1] * @param {number} p0 first value * @param {number} p1 second value * @param {number} m0 first tangent (tangent exiting from first value) * @param {number} m1 second tangent (tangent entering into second value) * @return {number} * * @author Alex Goldring * @copyright Company Named Limited (c) 2025 */ export function spline3_hermite(t, p0, p1, m0, m1) { const t2 = t * t; const t3 = t2 * t; const a = 2 * t3 - 3 * t2 + 1; const b = t3 - 2 * t2 + t; const c = t3 - t2; const d = 3 * t2 - 2 * t3; return a * p0 + b * m0 + c * m1 + d * p1; }