Direction Angle of 2D Vector in Terms of Arctangent

Theorem
Let $\mathbf a$ be a vector quantity embedded in a Cartesian plane $P$ expressed in component form as:
 * $\mathbf a = x \mathbf i + y \mathbf j$

Let $\theta$ denote the direction of $\mathbf a$.

Then:
 * $\theta = \begin{cases}

\map \arctan {\dfrac y x} & : x > 0 \\ \map \arctan {\dfrac y x} + \pi & : x < 0 \text{ and } y \ge 0 \\ \map \arctan {\dfrac y x} - \pi & : x < 0 \text{ and } y < 0 \\ \dfrac \pi 2 & : x = 0 \text{ and } y > 0 \\ -\dfrac \pi 2 & : x = 0 \text{ and } y < 0 \\ \text{undefined} & : x = 0 \text { and } y = 0 \end{cases}$

where:
 * $\arctan$ denotes the real arctangent function, defined on the real interval $\openint {-\dfrac \pi 2} {\dfrac \pi 2}$
 * $\theta$ is conventionally measured from the positive direction of the $x$-axis in the interval $\hointl {-\pi} \pi$.

Proof
Let $\mathbf a$ be such that one of the following holds:


 * $\mathbf a$ is in Quadrant $\text{I}$ or Quadrant $\text{IV}$
 * $\mathbf a$ is on the positive direction of the $x$-axis.

Then:
 * $x > 0$

and:
 * $-\dfrac \pi 2 < \theta < \dfrac \pi 2$

The components of $\mathbf a$ form the legs of a right triangle where:

Let $\mathbf a$ be such that one of the following holds:


 * $\mathbf a$ is in Quadrant $\text{II}$
 * $\mathbf a$ is on the negative direction of the $x$-axis.

Then:
 * $x < 0$
 * $y \ge 0$

and:
 * $\dfrac \pi 2 < \theta \le \pi$

Let $\mathbf a$ be in Quadrant $\text{III}$.

Then:
 * $x < 0$
 * $y < 0$

and:
 * $-\pi < \theta < \dfrac {-\pi} 2$

Let $\mathbf a$ be on the positive direction of the $y$-axis.

Then:
 * $x = 0$
 * $y > 0$

Then the arctangent of $\theta$ is undefined.

We have:

Let $\mathbf a$ be on the negative direction of the $y$-axis.

Then:
 * $x = 0$
 * $y < 0$

Then the arctangent of $\theta$ is undefined.

We have:

Finally, let $\mathbf a$ be the zero vector.

We have:
 * $x = 0$
 * $y = 0$

and hence:

Hence, $\theta$ can be described using the following piecewise function:

Hence the result.

Also defined as
Some sources define the codomain as the interval $\hointr 0 {2 \pi}$.

Also known as
This piecewise function is often presented in computer languages as $\map {\text {atan2} } {y, x}$.