Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating vector angles

Status
Not open for further replies.

ben146

Programmer
Jan 30, 2003
11
US
Hi all,
my ? is.is there a better way to calculate vector angles
than the code below?if u have a better way i would realy like to know.any help would be appreciated.take a look below.


void VectorAngles( const float *forward, float *angles )
{
float tmp, yaw, pitch;

if (forward[1] == 0 && forward[0] == 0)
{
yaw = 0;
if (forward[2] > 0)
pitch = 90.0;
else
pitch = 270.0;
}
else
{
yaw = (float)(atan2f(forward[1], forward[0]) * 180.0 / M_PI);

if (yaw < 0) yaw += 360.0;

tmp = (float)sqrt (forward[0]*forward[0] + forward[1]*forward[1]);

pitch = (float)(atan2f(forward[2], tmp) * 180 / M_PI);
}
angles[0] = pitch;
angles[1] = yaw;
angles[2] = 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top