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

This topic is 4071 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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)

##### Share on other sites
What angle would you like to get from a vector?

##### Share on other sites
Quote:
 Original post by RattenhirnWhat 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.

##### Share on other sites
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!

##### Share on other sites
Quote:
 Original post by RattenhirnOk, 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 :)

1. 1
Rutin
70
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633430
• Total Posts
3011825
• ### Who's Online (See full list)

There are no registered users currently online

×