Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this