Maths - Issues with Relative Angles

There are some issues with taking the relative angle between two angles, especially if we use this formula:
atan2(v2.y,v2.x) - atan2(v1.y,v1.x)
as discussed on this page.

It is useful to keep in mind that:

So, as an example, lets look at two vectors which are 90° (π/2) apart relative to each other. It should not matter what coordinate system we use as follows:

first and second quadrant If v1 is in the first quadrant and v2 is in the second we might get:
atan2(-1,1) - atan2(1,1)
= 3/4π - 1/4π
= π/2
quadrant 2 and 3 If v1 is in the second quadrant and v2 is in the third we might get:
atan2(-1,-1) - atan2(-1,1)
= -3/4π - 3/4π
= -π3/2
adding 2π gives:
= π/2
quadrant 3 and 4 If v1 is in the third quadrant and v2 is in the forth we might get:
atan2(1,-1) - atan2(-1,-1)
= -1/4π + 3/4π
= π/2
quadrant 4 and 1 If v1 is in the forth quadrant and v2 is in the first we might get:
atan2(1,1) - atan2(1,-1)
= 1/4π + 1/4π
= π/2

So the angle between the vectors is always π/2.

metadata block
see also:

Correspondence about this page
  • This page arose from a forum discussion with Jason about calculating relative angles here.

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover If you are interested in 3D games, this looks like a good book to have on the shelf. If, like me, you want to have know the theory and how it is derived then there is a lot for you here. Including - Graphics pipeline, scenegraph, picking, collision detection, bezier curves, surfaces, key frame animation, level of detail, terrain, quadtrees & octtrees, special effects, numerical methods. Includes CDROM with code.

Other Math Books

Terminology and Notation

Specific to this page here:


This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.