Getting an angle from look at vectors (and other stuff)

Started by
3 comments, last by chillypacman 16 years, 6 months ago
I'm looking for a generel purpouse math library that takes care of most basic maths such as a function that takes in a look at vector (such as D3DXVECTOR3(0.2, 1, 0.5)) and returns an angle of the direction. I'm working with DirectX (if thats relevent)
Advertisement
What angle would you like to get from a vector?
Quote:Original post by Rattenhirn
What angle would you like to get from a vector?


basic trigonometry stuff, like:

vector of (0, 1, 0.2) -> get angle between the y and z so...

/|
/ | 0.1
<---
0.2

or something like that.
Ok, basic trigonomy is covered by the c standard library.

Just include math.h.

To get the angle between y and z use:
double angle = atan2(y, z);

or if you don't need double precision:
float angle = atan2f(y, z);

Depending on which compiler you use, you may have to put "std::" before "atan2" or write "using namespace std;" somewhere in the file.

Hope that helps!
Quote:Original post by Rattenhirn
Ok, basic trigonomy is covered by the c standard library.

Just include math.h.

To get the angle between y and z use:
double angle = atan2(y, z);

or if you don't need double precision:
float angle = atan2f(y, z);

Depending on which compiler you use, you may have to put "std::" before "atan2" or write "using namespace std;" somewhere in the file.

Hope that helps!


yep that helped heaps.

Thank you :)

This topic is closed to new replies.

Advertisement