Created
September 16, 2015 16:53
-
-
Save hugooliveirad/c69bb6a72d381638e10d to your computer and use it in GitHub Desktop.
Angles fun
This file contains hidden or 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
// radians->degrees | |
function degrees(radians) { | |
return radians * 180 / Math.PI; | |
} | |
// gets two positions { x: Number, y: Number } and return | |
// angle between them in radians | |
function getAngle(pos1, pos2 = {x: 0, y: 0}) { | |
let [dx, dy] = [pos1.x - pos2.x, (pos1.y - pos2.y) * -1] | |
return Math.atan2(dy, dx); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment