Skip to content

Instantly share code, notes, and snippets.

@reikVdM
Forked from conorbuck/angle-between-points.js
Created April 9, 2020 01:34
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 reikVdM/321f6982647b0269864b3cdead1fa73b to your computer and use it in GitHub Desktop.
Save reikVdM/321f6982647b0269864b3cdead1fa73b to your computer and use it in GitHub Desktop.
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
// angle in radians
var angleRadians = Math.atan2(p2.y - p1.y, p2.x - p1.x);
// angle in degrees
var angleDeg = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment