UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

27 lines (21 loc) 869 B
/** * Returns the first-order partial derivative of a Hermite curve with control points p0, m0, p1, m1 at the parameter t in [0,1]. * * @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 * @param {number} m1 second tangent * @returns {number} * * @see spline3_hermite_integral */ export function spline3_hermite_derivative(t, p0, p1, m0, m1) { // see https://github.com/krishauser/Klampt/blob/0ed16608a3eceee59d04383a17c207ebc33a399f/Python/klampt/math/spline.py#L22 const t2 = t * t const dcx1 = (6.0 * t2 - 6.0 * t) const dcx2 = (-6.0 * t2 + 6.0 * t) const dcv1 = 3.0 * t2 - 4.0 * t + 1.0 const dcv2 = 3.0 * t2 - 2.0 * t return dcx1 * p0 + dcx2 * p1 + dcv1 * m0 + dcv2 * m1 }