Skip to content

Instantly share code, notes, and snippets.

@ehgoodenough
Created September 18, 2016 18:26
Show Gist options
  • Save ehgoodenough/82952ec65d0a68d4a6fb314acc0e56d5 to your computer and use it in GitHub Desktop.
Save ehgoodenough/82952ec65d0a68d4a6fb314acc0e56d5 to your computer and use it in GitHub Desktop.
function getDirection(x, y) {
var angle = Math.atan2(y, x)
return angle
}
function getDistance(x, y) {
return Math.sqrt(x*x + y*y) || 0
}
function getVector(p1, p2) {
var x = p2.x - p1.x
var y = p2.y - p1.y
return {
direction: getDirection(x, y),
distance: getDistance(x, y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment