JSFiddle - React, Tailwind, and code Playground
by clauswilke
JavaScript
const tau = 2*3.1415
const interp5 = (phi, s) => {
// normalize to 0 to 1
let t = (phi % tau) / tau, t2 = t*t, t4 = t2*t2,
u = 1-t, u2 = u*u,
// calculate interpolation, +-2 is a tuning constant, can be different
a = s + 2,
b = s - 2,
// fifth-order polynomial
y = t*t4 + 5*t4*u + a*10*t*t2*u2 + b*10*t2*u2*u
// return as angle
return tau*y
}
const interpolateAngles = (phi, s, phioff = 0) =>
interp5(phi + phioff, s) - interp5(phioff, s)
let s = 0.9
console.log(interpolateAngles(0, s))
console.log(interpolateAngles(3.14, s))
console.log(interpolateAngles(2*3.14, s))
console.log(interpolateAngles(3.14, s, 3.14))