Created
March 4, 2020 14:12
-
-
Save adamdehaven/35cd2570e4e37c7ad815946cde742fc7 to your computer and use it in GitHub Desktop.
Get the angle (in degrees or radians) 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
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