Go Back   AC3D Forums > Technical > AC3D Developers
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 17th May 2005, 12:34 AM   #1
briandavis
Junior Member
Member
 
Join Date: Jul 2004
Posts: 10
Default Determining roll, pitch, and yaw from a normalized vector

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.
briandavis is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -4. The time now is 06:54 PM.


AC3D Forum
(C) Inivis Limited 2020