Skip to content

Instantly share code, notes, and snippets.

@RezaAmd
Last active September 23, 2023 10:47
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 RezaAmd/f0299e9f59c1906819570170d4da99f0 to your computer and use it in GitHub Desktop.
Save RezaAmd/f0299e9f59c1906819570170d4da99f0 to your computer and use it in GitHub Desktop.
Calculate two points angle degree in 2D graph
// JavaScript:
const angleCalculator = function(ax, ay, bx, by)
{
return Math.atan2(by - ay, bx - ax) * 180 / Math.PI
}
@RezaAmd
Copy link
Author

RezaAmd commented Sep 23, 2023

For example :

image
A[1x , 1y] - B[2x , 2y]

// Output: 45

image
A[-1x , -2y] - B[3x , 0y]

// Output: 26.56505117707799

image
A[1x , -3y] - B[1x , 2y]

// Output: 90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment