math - Using atan2 to find angle between two vectors -


i understand that:

atan2(vector.y, vector.x) = angle between vector , x axis.

but wanted know how angle between two vectors using atan2. came across solution:

atan2(vector1.y - vector2.y, vector1.x - vector2.x) 

my question simple:

will 2 following formulas produce same number?

  • atan2(vector1.y - vector2.y, vector1.x - vector2.x)

  • atan2(vector2.y - vector1.y, vector2.x - vector1.x)

if not: how know vector comes first in subtractions?

thanks

 atan2(vector1.y - vector2.y, vector1.x - vector2.x) 

is angle between difference vector (connecting vector2 , vector1) , x-axis, problably not meant.

the (directed) angle vector1 vector2 can computed as

angle = atan2(vector2.y, vector2.x) - atan2(vector1.y, vector1.x); 

and may want normalize range 0 .. 2 * pi:

if (angle < 0) angle += 2 * m_pi; 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -