Skip to content

Instantly share code, notes, and snippets.

@pije76
Forked from timohausmann/gist:4997956
Created August 29, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pije76/dd62555bea2d1aa227acfc51974fc49a to your computer and use it in GitHub Desktop.
Save pije76/dd62555bea2d1aa227acfc51974fc49a 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