-
-
Save codergautam/a574787d79c9809cc2e22d5187e9d02f to your computer and use it in GitHub Desktop.
The best way to interpolate 2D angles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
// |
The updated code is incorrect: amt+(end-start)*amt
should be start+(end-start)*amt
How did I miss this?! Thanks so much for catching this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gotcha, I have updated it