get angle from sin and cos

Started by
4 comments, last by Dirk Gregorius 18 years ago
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?
Advertisement
asin(value) and acos(value) will return the angles in radians.
You might also try atan2(); it's a little more stable.
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).
Imagination's the limit.
Thanks jyk.
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

This topic is closed to new replies.

Advertisement