Problem with Atan2

Tull

New member
Joined
Apr 14, 2017
Messages
5
Hi folks.

I'm struggling to understand an odd problem I've encountered with Atan2.

I have two vectors and I need to measure the difference of angle.

For testing I have the two vectors 50,0 and 0,50. These when plotted on paper would show a very obvious angle of 90 degrees.

However, when I put these through Atan2 - Angle = Math.Atan2(b.Y - a.Y, b.X - a.X) - I get a result of 65 degrees.

I know my vectors are good, absolutely, they're double checked. So what is going wrong here, am I misunderstanding the use of Atan2?

Thanks folks.

(If this is in the wrong forum please feel free to move it somewhere else.)
 
I have two vectors and I need to measure the difference of angle.
By "the difference of angle", do you mean "the angle formed by the two vectors"?

For testing I have the two vectors 50,0 and 0,50.
By "50,0 and 0,50", do you mean something like "<50, 0> and <0, 50>"?

These when plotted on paper would show a very obvious angle of 90 degrees.
Assuming you started the vectors at the origin and plotted their endpoints as being on the x- and y-axes, yes, this is true.

However, when I put these through Atan2 - Angle = Math.Atan2(b.Y - a.Y, b.X - a.X) - I get a result of 65 degrees.
What do you mean by "Atan2 - Angle = Math.Atan2..."? What is this? How do the vectors' components relate? What are a, b, X, and Y? Assuming that "Atan" means "arctangent", assuming that the "2" following means "squared" (so you meant to say "^2"), what is the argument of the arctangent? What do you mean by "Angle"? What is the meaning of "Math.Atan2"? How did you "get a result of 65 degrees"?

Please provide all definitions and show all work. Thank you! ;)
 
What in the world do you mean by "ATan2" and "Math.ATan2"? Are you using a computer algebra system? If so, which?
 
Hi folks.

I'm struggling to understand an odd problem I've encountered with Atan2.

I have two vectors and I need to measure the difference of angle.

For testing I have the two vectors 50,0 and 0,50. These when plotted on paper would show a very obvious angle of 90 degrees.

However, when I put these through Atan2 - Angle = Math.Atan2(b.Y - a.Y, b.X - a.X) - I get a result of 65 degrees.

I know my vectors are good, absolutely, they're double checked. So what is going wrong here, am I misunderstanding the use of Atan2?

Thanks folks.

(If this is in the wrong forum please feel free to move it somewhere else.)

Typically atan2 [ Math.atan2 ] measures the angle between the positive x axis and a vector. If you have a vector <x, y> the angle between it and the x axis would be
angle_between = atan2(y, x)
where the answer would be in radians. Also, typically, the cut is along the negative x axis so that a point "just above" the negative x axis, i.e. something like a=<-100, 0.1>, would have an angle "close to" π\displaystyle \pi and a point "just below" the negative x axis, i.e. something like b=<-100, -0.1>, would have an angle close to π\displaystyle -\pi.

As far as the angle between two vectors goes, you could compute both of the angles and subtract angle. However you need to be careful doing this. As an example the angle from vector a to vector b above, which crosses the negative x axis, would be close to 0. However, if you do the subtraction you get about 2π\displaystyle 2\, \pi . The reason for the difference is that you passed over the "cut line" so that you need to subtract the answer from 2π\displaystyle 2\pi. Remember also that you are getting the angle from one vector to another which maybe greater than π\displaystyle \pi

EDIT: BTW, do you mean to say 45 degrees instead of 65 degrees?
 
Last edited:
I didn't explain very well, so I opened a new topic with everything stated a bit clearer. But for clarification, Ishuda, yes to all. And the calculation is of the two vectors, A and B with X being the X component and Y being the Y component.

I have since learnt the calculation I actually need is Math.Atan2(b.Y, b.X) - Math.Atan2(a.Y, a.X)

What I need is the angle of intersection of the two vectors, there always will be an intersection as 2 objects have already collided at this point. But I'm confused with the results.

I need an angle of difference from vector A to vector B, where A is always 0 degrees or radians. Which is what I was expecting from the calculation above. Do I need to take quadrants into consideration, or anything else that might through my expectations?

Thanks.
 
Top