Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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;

Thanks!

Very useful thank you!

allada commented Jan 11, 2015

+1

adius commented May 6, 2015

Angle between two points makes no sense. You mean angle between two vectors.

PAEz commented Jun 10, 2015

@adius To the educated it makes no sense and to the uneducated it makes perfect sense ;)

jack2ky commented Oct 28, 2015

@adius Thanks for the clarification. @adius

McFarts commented Dec 6, 2015

thx sir i love you

Cicim commented Feb 19, 2016

Great job. Very useful!

Thank you! Really useful for a Maths n00b like me! Googles Math.atan2...

uatec commented Mar 14, 2016

@adius, @PAEz, not the angle between two points OR the angle between two vectors, but the angle of the vector from point A to point B.

Norik-P commented Mar 18, 2016

Thank you!

+1 :) helpalot

akaguny commented Apr 20, 2016

it`s the angle beetween 2 radius vectors?

Samueleroux commented Apr 26, 2016 edited

Thanks

chardos commented Jul 24, 2016

Thanks man!

Awesome! Thanks

LiamKarlMitchell commented Aug 26, 2016 edited

Thanks
I used Math.atan2(v.e(2), v.e(1)) to get the angle of a Sylvester js unit vector / direction from a vector.
For some reason angleFrom kept giving me null hah.

Thanks

Like it. Thanks

xbeat commented Feb 7, 2017

Thanks

+1. Thank you!! Apparently it's been a while since geometry 😝

baladkb commented Apr 17, 2017

Thanks.

+1

Dvoikin commented May 5, 2017

+1

Awesome !

parwoto commented Jul 8, 2017

Thanks

4 usefull lines of code

Great!

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