In two dimensional space, if we want a vector corresponding to a given angle $t$, we can do:
$(x, y) = ( \cos(t), \sin(t) )$
But what about the reverse? We have a vector, and want to know the angle. A common solution is to use arctan:
$t = \arctan( \frac{y}{x} )$
Here $\frac{y}{x}$ represents the gradient of the vector. So it has a meaningful value even when $x = 0$.
Trivia: Many program languages will fail to perform that calculation, because division by zero will produce an error. They usual address this by offering an alternative function which takes two arguments: atan2(y, x)
.
But a notable exception is Javascript, which has the concept of +Infinity
and -Infinity
as numbers, and can perform this calculation even when x = 0.
$ node
> Math.atan( 1 / 0 )
1.5707963267948966 (Pi/2)
> Math.atan( -1 / 0 )
-1.5707963267948966 (-Pi/2)
Another language which can perform this calculation is Haskell.
Inspired by Qiaochu Yuan's comment.