A unit vector V is the result of applying first a pitch and then yaw to the vector (0,0,1). Pitch is always between –89 degrees and 89 degrees.
I am writing a function which determines the yaw angle component (in radians) of this transform, given the transformed vector.
The problem with my code is that asin() returns a value from -PI/2 to PI/2 which is ambiguous for cases like 45 degrees and 135 degrees. How can I resolve this ambiguity?
Here is my code ...
float ExtractYaw(Vec &transformedVec)
{
/*
After applying pitch (of angle theta) to V the resulting vector is
| 0 |
| -sin(theta) |
| cos(theta) |
| 1 |
After applying yaw (of angle phi) to the above vector the resulting vector is
| sin(phi) * cos(theta) |
| -sin(theta) |
| cos(phi) * cos(theta) |
| 1 |
We can now solve for theta ...
*/
float theta = -asin(transformedVec.y);
// We can now use theta to solve for phi by using either x or z
// (I use x)
float cosTheta = cos(theta);
float phi = asin(transformedVec.x / cosTheta);
return phi;
}











