Jump to content
  • Advertisement
Sign in to follow this  
toan1982

get angle from sin and cos

This topic is 4610 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 have two value : sin(a) and cos(a). I want to get angle value (degree or radian) for a. What functions (C++) should i use to get a?

Share this post


Link to post
Share on other sites
Advertisement
asin and acos will return you the angle, but you may need to evaluate both since, for example, you get the same value when evaluating sin50 and sin130 (and asin will always return 50). So, you evaluate both and check wether they're positive/negative and make the appropiate corrections.

Saludos,
José Jorge (GeoMX).

Share this post


Link to post
Share on other sites
You can either use asin() or acos(), but I recommend using atan2(). Example:

float s = sin(angle);
float c = cos(angle);

float angle = atan2(s, c);

This makes sure you get the right sign of the angle. This is also very helpful when working with quaternions...

HTH,

-Dirk

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!