Published
Edited
May 22, 2019
1 fork
21 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
slerp = (a, b, t) => {
const k = Math.acos(dot(a, b));
const q = Math.sin(k * (1 - t));
const p = Math.sin(k * t);
return unitLerp(a, b, q, p);
}
Insert cell
Insert cell
fslerp = function fslerp(a, b, t) {
if (t === 0.5) return unitLerp(a, b, t, t);
const d = dot(a, b);
if (d < 0) { // angle > 90; recurse into one of the halves
const m = unitLerp(a, b, 0.5, 0.5);
return t < 0.5 ? fslerp(a, m, t * 2) : fslerp(m, b, t * 2 - 1);
}
const A = 1.0904 + d * (-3.2452 + d * (3.55645 - d * 1.43519));
const B = 0.848013 + d * (-1.06021 + d * 0.215638);
const K = A * (t - 0.5) * (t - 0.5) + B;
const p = t + t * (t - 0.5) * (t - 1) * K;
return unitLerp(a, b, 1 - p, p);
}
Insert cell
Insert cell
unitLerp = ([ax, ay], [bx, by], t0, t1) => {
const x = ax * t0 + bx * t1;
const y = ay * t0 + by * t1;
const d = Math.sqrt(x * x + y * y);
return [x / d, y / d];
}
Insert cell
Insert cell
dot = ([ax, ay], [bx, by]) => ax * bx + ay * by
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more