Skip to content

Instantly share code, notes, and snippets.

@caryfuk
Created June 20, 2016 15:04
Show Gist options
  • Save caryfuk/1621cd011933cee40de8420eb1077db7 to your computer and use it in GitHub Desktop.
Save caryfuk/1621cd011933cee40de8420eb1077db7 to your computer and use it in GitHub Desktop.
compute angle on unit circle (alternative to built in Math.atan2)
const angle = (x, y) => {
let result = Math.atan(y / x);
if (x < 0) {
result += Math.PI;
} else if (y < 0) {
result += 2 * Math.PI;
}
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment