Skip to content

Instantly share code, notes, and snippets.

@aaronjanse
Created June 20, 2016 21:42
Show Gist options
  • Save aaronjanse/4068b058f8dbc34b4d3a9eedc8b2cbe0 to your computer and use it in GitHub Desktop.
Save aaronjanse/4068b058f8dbc34b4d3a9eedc8b2cbe0 to your computer and use it in GitHub Desktop.
find the smallest distance between two angles
// 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;
}
@patrickheng
Copy link

Very useful util, thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment