-
-
Save pije76/dd62555bea2d1aa227acfc51974fc49a 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