logo

Definition of the Arctan2 Function 📂Functions

Definition of the Arctan2 Function

Definition

Arc Tangent 2 $\arctan 2 : \left( \mathbb{R}^{2} \setminus \left\{ (0,0) \right\} \right) \to \mathbb{R}$ is defined as follows. $$ \arctan 2 : \left( r \sin \theta , r \cos \theta \right) \mapsto \theta $$ $r > 0$ is any positive number.

Description

Arc Tangent 2 is used in fields such as mechanical engineering to supplement the information that is insufficient with Arc Tangent $\arctan$, considering it provides the tangent ${{ \sin } \over { \cos }}$, even when the position information $r \cos$, $r \sin$ is known, and it compensates for the problem of losing the sign. As it is evident from its domain, it is still undefined in $(0,0)$.

Difference from $\arctan$

As you can see, the Arc Tangent cannot distinguish between $(1,1)$ and $(-1,-1)$, whereas Arc Tangent 2 can.

Convention

When it is $x = \cos$ and $y = \sin$, it is $\theta = \arctan 2 (y,x)$ in C language and MATLAB, but in some cases, it is $\theta = \arctan 2 (x,y)$. If it follows the sine-cosine order, $\arctan 2 (\sin, \cos)$ feels natural, and if it follows the x-y order, $\arctan 2 (x,y)$ feels naturally different, so one must pay attention accordingly.

As can be felt even from the difference in these conventions, Arc Tangent 2 is not so much about having some significant mathematical meaning as it is about purely being used for practicality by adding the number 2. It introduces the following theorem, which frequently appears in Inverse Kinematics.

Theorem

Angle when a linear combination of trigonometric functions is given

$$ a \cos \theta + b \sin \theta = c $$ If the linear combination of trigonometric functions is as $c \in \mathbb{R}$, the angle $\theta$ is as follows. $$ \begin{align*} \cos \theta =& {{ ac \pm \sqrt{ b^{2} \left( a^{2} + b_{2} - c^{2} \right) } } \over { a^{2} + b^{2} }} \\ \sin \theta =& {{ b^{2} c \mp a \sqrt{ b^{2} \left( a^{2} + b^{2} - c^{2} \right) } } \over { b \left( a^{2} + b^{2} \right) }} \\ \theta =& \arctan2 \left( \sin \theta , \cos \theta \right) \end{align*} $$ Especially when $c = 0$, the following simpler form can be used. $$ \begin{align*} \cos \theta =& \pm \sqrt{ {{ b^{2} } \over { a^{2} + b^{2} }} } \\ \sin \theta =& \mp {{ a } \over { b }} \sqrt{ {{ b^{2} } \over { a^{2} + b^{2} }} } \\ \theta =& \arctan2 \left( \sin \theta , \cos \theta \right) \end{align*} $$

Proof

Strategy: Fundamentally uses the quadratic formula.

Quadratic Formula: For the quadratic equation $ax^{2}+bx+c=0$ (where, $a\neq 0$) $$ x=\dfrac{ -b\pm \sqrt { b^{2}-4ac } }{2a} $$


Since $\sin \theta = \sqrt{ 1 - \cos^{2} \theta}$, $$ \begin{align*} & a \cos \theta + b \sin \theta = c \\ \implies & a \cos \theta - c = - b \sin \theta \\ \implies & a^{2} \cos^{2} \theta - 2 ac \cos \theta + c^{2} = b^{2} \left( 1 - \cos^{2} \theta \right) \\ \implies & a^{2} \cos^{2} \theta - 2 ac \cos \theta + c^{2} = b^{2} \left( 1 - \cos^{2} \theta \right) \\ \implies & \left( a^{2} + b^{2} \right) \cos^{2} \theta - 2 ac \cos \theta + \left( c^{2} - b^{2} \right) = 0 \end{align*} $$ following the quadratic formula when the coefficient of the first term is twice, $$ \begin{align*} \cos \theta =& {{ ac \pm \sqrt{ a^{2} c^{2} - \left( a^{2} + b^{2} \right) \left( c^{2} - b^{2} \right) } } \over { a^{2} + b^{2} }} \\ =& {{ ac \pm \sqrt{ - b^{2} c^{2} + a^{2} b^{2} + b^{4} } } \over { a^{2} + b^{2} }} \end{align*} $$ Meanwhile, since $\sin \theta = {{ c - a \cos \theta } \over { b }}$, $$ \begin{align*} \sin \theta =& {{ c - a \cos \theta } \over { b }} \\ =& {{ c - a {{ ac \pm \sqrt{ b^{2} \left( a^{2} + b_{2} - c^{2} \right) } } \over { a^{2} + b^{2} }}} \over { b }} \\ =& {{ c } \over { b }} - {{ a^{2} c \pm a \sqrt{ b^{2} \left( a^{2} + b_{2} - c^{2} \right) } } \over { b \left( a^{2} + b^{2} \right) }} \\ =& {{ c \left( a^{2} + b^{2} \right) } \over { b }} - {{ a^{2} c \pm a \sqrt{ b^{2} \left( a^{2} + b_{2} - c^{2} \right) } } \over { b \left( a^{2} + b^{2} \right) }} \\ =& - {{ b^{2} c \pm a \sqrt{ b^{2} \left( a^{2} + b_{2} - c^{2} \right) } } \over { b \left( a^{2} + b^{2} \right) }} \end{align*} $$ Now that we know the sine and cosine, we get the desired $\theta = \arctan2 \left( \sin \theta , \cos \theta \right)$ in Arc Tangent 2.