Created
June 20, 2016 21:42
-
-
Save aaronjanse/4068b058f8dbc34b4d3a9eedc8b2cbe0 to your computer and use it in GitHub Desktop.
find the smallest distance between two 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
// from http://stackoverflow.com/a/7869457 | |
// converted to js code | |
// x and y are the angles in radians | |
function getDifference(x, y) { | |
var a = x-y; | |
a = (function(i, j) {return i-Math.floor(i/j)*j})(a+Math.PI, Math.PI*2); // (a+180) % 360; this ensures the correct sign | |
a -= Math.PI; | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very useful util, thank you !