Skip to content

Instantly share code, notes, and snippets.

@adamdehaven
Created March 4, 2020 14:12
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 adamdehaven/35cd2570e4e37c7ad815946cde742fc7 to your computer and use it in GitHub Desktop.
Save adamdehaven/35cd2570e4e37c7ad815946cde742fc7 to your computer and use it in GitHub Desktop.
Get the angle (in degrees or radians) between two points
let pointOne = {
x: 20,
y: 20,
}
let pointTwo = {
x: 40,
y: 40,
}
// Get angle in Radians
const angleRadians = Math.atan2(pointTwo.y - pointOne.y, pointTwo.x - pointOne.x)
// Get angle in degrees
const angleDeg = Math.atan2(pointTwo.y - pointOne.y, pointTwo.x - pointOne.x) * 180 / Math.PI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment