Angle from two vectors and Atan2 (objects approaching each other)

Tull

New member
Joined
Apr 14, 2017
Messages
5
Hi folks. I posted a question about Atan2 and it's use a few days ago, but I don't think I explained enough about the problem.

I have two objects approaching each other, each has a random velocity vector. I first get the Normal of the collision angle from object 1, then calculate the tangent (90 degree rotation as all objects are circles), then calculate the angle between the approach of object 1 and the tangent. Everything to this point is perfect.

Then I use the following line of code:
- Radian = Math.Atan2(b.Y, b.X) - Math.Atan2(a.Y, a.X)
to obtain the angle of intersection of the two object's vectors. I believe this is correct, but only because I've picked it up from a forum somewhere on a similar subject, lord knows where.

I need this angle to then calculate a rotational deflection force of two colliding objects. I have the elastic bounce sorted, that's working perfectly. I'm not following the exact rules of physics here as I found that to be far too complicated, so I'm trying to 'fluff' an approximation, although the final calculation will include momentum and mass.

The problem I'm stumbling over is the result of the Atan2 calculation, I'm getting positive and negative values which I would expect depending if the collision were to the 'left or right', but I'm not totally understanding the output.

So, what exactly does the above Atan2 calculation give me? Does it return a true value between the two vectors, or against some axis? How is it affected by positive and negative input vectors? Do I need to be aware of quadrants in the returned data? Is an 'up/down' collision going to give a different result to a 'left/right' collision?

What I need is the angle between the 2 vectors without any interference, no matter of direction, with Vector A being treated as 0 degrees.

Any help would be greatly appreciated, I've been banging my head against this brick for days now!!

Many thanks.
(I hope this makes sense, I'm not a math person.)
 
Last edited by a moderator:
Hi folks. I posted a question about Atan2 and it's use a few days ago, but I don't think I explained enough about the problem.

I have two objects approaching each other, each has a random velocity vector. I first get the Normal of the collision angle from object 1, then calculate the tangent (90 degree rotation as all objects are circles), then calculate the angle between the approach of object 1 and the tangent. Everything to this point is perfect.

Then I use the following line of code:
- Radian = Math.Atan2(b.Y, b.X) - Math.Atan2(a.Y, a.X)
to obtain the angle of intersection of the two object's vectors. I believe this is correct, but only because I've picked it up from a forum somewhere on a similar subject, lord knows where.

I need this angle to then calculate a rotational deflection force of two colliding objects. I have the elastic bounce sorted, that's working perfectly. I'm not following the exact rules of physics here as I found that to be far too complicated, so I'm trying to 'fluff' an approximation, although the final calculation will include momentum and mass.

The problem I'm stumbling over is the result of the Atan2 calculation, I'm getting positive and negative values which I would expect depending if the collision were to the 'left or right', but I'm not totally understanding the output.

So, what exactly does the above Atan2 calculation give me? Does it return a true value between the two vectors, or against some axis? How is it affected by positive and negative input vectors? Do I need to be aware of quadrants in the returned data? Is an 'up/down' collision going to give a different result to a 'left/right' collision?

What I need is the angle between the 2 vectors without any interference, no matter of direction, with Vector A being treated as 0 degrees.

Any help would be greatly appreciated, I've been banging my head against this brick for days now!!

Many thanks.
(I hope this makes sense, I'm not a math person.)
First Math.atan2 [or just atan2 or sometimes ArcTan], see
https://en.wikipedia.org/wiki/Atan2

174e1931034cc4c35aaedfdb2a3cd06c9247d850


Note that there is a jump of 2π\displaystyle 2\pi as you cross the negative x axis [the cut line].

Just as one must be careful in defining atan2, one must be careful about defining the angle between two vectors. Example: If we let a=<-1,1> and b=<-1,-1>, the angle a makes with the positive x axis is 3π/4\displaystyle 3\pi/4 and the angle b makes is 3π/4\displaystyle -3\pi/4. Now, the angle between a and b is π/2\displaystyle \pi/2. However, if we go from a to b the difference in angles is 6π/4\displaystyle 6\pi/4 = 3π/4\displaystyle 3\pi/4 - (3π/4\displaystyle -3\pi/4). The reasons the answers don't agree is that you have crossed the cut line and have to take the 2π\displaystyle 2\pi jump out. To do this we subtract the difference from 2π\displaystyle 2\pi and both answers are now the same.
 
Last edited:
Top