If you have a clock, where it's 5 minutues to 12, angle is 5 minutes.
If it's 5 min after 12, angle is also 5 minutes.
Now, you want 5 to 12 to become -5 mins?
So question is: Is minute pointer left or right from hour pointer?
If the clock is on the x-z plane, y of all vectors are equal, the whole system is projectet allready on the xz plane.
It's 2-dimensional and you can feed the atan2 function with x and z values of the unit vectors,
as they represent sine and cosine. 11 o clock gives -5, 12 o clock gives 0, and 1 o clock gives 5.
So the difference between those angles contains a sign too.
But what do you do if the clock is not aligned to any easy plane?
This gets much more interresting and usefull...
Let's call the 12 o clock vec Xaxis.
You take the cross product between this and the 11 o clock vector.
This gives a vector that is perpendicular to both of them, so it points straight outwards the clock.
Let's normalize this new vector and call it the Yaxis.
Do it again and cross Yaxis with Xaxis, this gives the Zaxis vector pointing to 3 o clock.
Now you can take dot product from 11 o clock vec and the Zaxis: This gives the sine:
If it is negative, then angle is negative, and vector is on the left side from 12 o clock Xaxis.
So you got the answer, but you got more than that:
You got a 3 dimensional orthogonal coordinate system with all 3 basis vectors,
together with the position of the clock center you get a nice transformation matrix.
This leads to the right question: In relation to which space do i want to know that angle, and around which axis is that angle?
Now you can take a random point from global space and do the following:
global -= clockCenter
local.x = Xaxis.Dot(global)
local.y = Yaxis.Dot(global)
local.z = Zaxis.Dot(global)
You have transformad the point from global to local clock space.
Now you can again take the angle about Yaxis using atan2 (local.x, local.z) - don't forget to zero y and normalize first.
You can also rotate all 3 basis vectors from one space to another and so on...
Imagine the Orientation in 3D space by looking at the 3 basis vectors to become handy with transformation matrices.
And imagine the Rotation in 3D Space as a single angle in combination with a single axis! 3 angles are not good.
This is where quaternions become handy, but that may be part of the next lesson, depending on: What the hell do you wan't to do with that damn angle ???
