Created
September 18, 2016 18:26
-
-
Save ehgoodenough/82952ec65d0a68d4a6fb314acc0e56d5 to your computer and use it in GitHub Desktop.
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
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