Skip to content

Instantly share code, notes, and snippets.

@timohausmann
Last active May 20, 2019 14:14
Show Gist options
  • Save timohausmann/4997956 to your computer and use it in GitHub Desktop.
Save timohausmann/4997956 to your computer and use it in GitHub Desktop.
Javascript Math: get degree between two points
/**
* 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