Skip to content

Instantly share code, notes, and snippets.

View codergautam's full-sized avatar

Coder Gautam codergautam

View GitHub Profile
@codergautam
codergautam / betterAngleLerp.js
Last active October 19, 2022 02:37 — forked from shaunlebron/angleLerp.js
The best way to interpolate 2D angles
//note: degrees only
const lerp = (start,end,amt) => start+(end-start)*amt
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
const repeat = (t, m) => clamp(t - Math.floor(t / m) * m, 0, m);
function lerpTheta(a, b, t) {
const dt = repeat(b - a, 360);
return lerp(a, a + (dt > 180 ? dt - 360 : dt), t);
}