@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
27 lines (21 loc) • 769 B
JavaScript
/**
* 3-rd (cubic) degree bezier curve
* @see https://www.youtube.com/watch?v=jvPPXbo87ds&t=234s
* @see https://en.wikipedia.org/wiki/B%C3%A9zier_curve
* @param {number} t factor value between 0..1
* @param {number} p0 start point
* @param {number} p1 control point
* @param {number} p2 control point
* @param {number} p3 end point
* @returns {number}
*/
export function spline_bezier3(t, p0, p1, p2, p3) {
// first we compute necessary factors for each point
const nt = 1 - t;
const nt_2 = nt * nt;
const nt_3 = nt_2 * nt;
const t_2 = t * t;
const t_3 = t_2 * t;
// combine factors with point values to produce final result
return nt_3 * p0 + 3 * nt_2 * t * p1 + 3 * nt * t_2 * p2 + t_3 * p3;
}