• Advertisement
Sign in to follow this  

get angle from sin and cos

This topic is 4340 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