Hi,
As an exercise, I am taking the yaw and pitch angles of my simple
simulator and determining the 3D vector that those angles would create.
I am then wanting to take that vector and reverse the process to verify
the yaw and pitch angles. I've supplied my test code below, and as is
indicated by the output, you can see that neither attempt at retrieving
the original pitch and yaw were successful. In my world, X goes into the screen and Z is up.
Any help would be greatly appreciated!
Incidentally, I am planning to use this concept to 'walk' through a scene while looking at a particular point in 3d space.
Code:
#include "math.h"
#include "stdio.h"
float PI = 3.141592654f;
float Rad2Deg = 180 / PI;
float Deg2Rad = PI / 180;
int main(int argc, char* argv[])
{
float pitch = 10.0;
float yaw = 98.0;
pitch *= Deg2Rad;
yaw *= Deg2Rad;
float x, y, z;
x = (float)(cos(pitch) * cos(yaw));
y = (float)sin(yaw);
z = (float)(sin(pitch) * cos(yaw));
float len = (float)sqrt(x * x + y * y + z * z);
float verify_pitch = (float)atan2(z, len);
float verify_yaw = (float)atan2(y, x);
printf(" verify_pitch = %0.5f , pitch = %0.5f\n", verify_pitch,
pitch);
printf(" verify_yaw = %0.5f , yaw = %0.5f\n", verify_yaw, yaw);
scanf("done...\n");
// yields the following output
// verify_pitch = -0.02416 , pitch = 0.17453
// verify_yaw = 1.70833 , yaw = 1.71042
return 0;
}
Thanks for any insights into this problem.