Skip to content

Instantly share code, notes, and snippets.

@hugooliveirad
Created September 16, 2015 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugooliveirad/c69bb6a72d381638e10d to your computer and use it in GitHub Desktop.
Save hugooliveirad/c69bb6a72d381638e10d to your computer and use it in GitHub Desktop.
Angles fun
// 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