How to calculate the inverse tan?

I use UIAccelerationfor rotation. I have the opposite side, the adjacent side, but I want to calculate tan-1 (y / x) the inverse tan.

0
source share
3 answers

Always use atan2 (y, x) instead of atan (y / x) for two reasons. One is mentioned by David Maimood (problems with x = 0). Another is that atan2 () works with the full range from - & pi; to + π; while atan () gives only the result between - π / 2 and + π / 2 and cannot distinguish between (x, y) = (2,2) and (x, y) = (-2, -2), since you lose sign information when doing the division, and pass only the quotient y / x to atan ().

+9
source

C math.h:

#include <math.h>

...
float theta = atan2f(y, x);
...
+4

atan2(y, x)- this is the same as, atan(y/x)but it can deal with the case when x = 0(i.e. a vertical line up or down), without dealing with positive and negative infinity.

+3
source

All Articles