Last active
May 20, 2019 14:14
-
-
Save timohausmann/4997956 to your computer and use it in GitHub Desktop.
Javascript Math: get degree between two points
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
/** | |
* return the angle between two points. | |
* | |
* @param {number} x1 x position of first point | |
* @param {number} y1 y position of first point | |
* @param {number} x2 x position of second point | |
* @param {number} y2 y position of second point | |
* @return {number} angle between two points (in radian) | |
*/ | |
Math.getAngle = function( x1, y1, x2, y2 ) { | |
var dx = x1 - x2, | |
dy = y1 - y2; | |
return Math.atan2(dy,dx); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment