logo

Definition of the Arctan2 Function 📂Functions

Definition of the Arctan2 Function

Definition

Arc Tangent 2 arctan2:(R2{(0,0)})R\arctan 2 : \left( \mathbb{R}^{2} \setminus \left\{ (0,0) \right\} \right) \to \mathbb{R} is defined as follows. arctan2:(rsinθ,rcosθ)θ \arctan 2 : \left( r \sin \theta , r \cos \theta \right) \mapsto \theta r>0r > 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\arctan, considering it provides the tangent sincos{{ \sin } \over { \cos }}, even when the position information rcosr \cos, rsinr \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)(0,0).

Difference from arctan\arctan

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

Convention

When it is x=cosx = \cos and y=siny = \sin, it is θ=arctan2(y,x)\theta = \arctan 2 (y,x) in C language and MATLAB, but in some cases, it is θ=arctan2(x,y)\theta = \arctan 2 (x,y). If it follows the sine-cosine order, arctan2(sin,cos)\arctan 2 (\sin, \cos) feels natural, and if it follows the x-y order, arctan2(x,y)\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

acosθ+bsinθ=c a \cos \theta + b \sin \theta = c If the linear combination of trigonometric functions is as cRc \in \mathbb{R}, the angle θ\theta is as follows. cosθ=ac±b2(a2+b2c2)a2+b2sinθ=b2cab2(a2+b2c2)b(a2+b2)θ=arctan2(sinθ,cosθ) \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=0c = 0, the following simpler form can be used. cosθ=±b2a2+b2sinθ=abb2a2+b2θ=arctan2(sinθ,cosθ) \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 ax2+bx+c=0ax^{2}+bx+c=0 (where, a0a\neq 0) x=b±b24ac2a x=\dfrac{ -b\pm \sqrt { b^{2}-4ac } }{2a}


Since sinθ=1cos2θ\sin \theta = \sqrt{ 1 - \cos^{2} \theta}, acosθ+bsinθ=c    acosθc=bsinθ    a2cos2θ2accosθ+c2=b2(1cos2θ)    a2cos2θ2accosθ+c2=b2(1cos2θ)    (a2+b2)cos2θ2accosθ+(c2b2)=0 \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, cosθ=ac±a2c2(a2+b2)(c2b2)a2+b2=ac±b2c2+a2b2+b4a2+b2 \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θ=cacosθb\sin \theta = {{ c - a \cos \theta } \over { b }}, sinθ=cacosθb=caac±b2(a2+b2c2)a2+b2b=cba2c±ab2(a2+b2c2)b(a2+b2)=c(a2+b2)ba2c±ab2(a2+b2c2)b(a2+b2)=b2c±ab2(a2+b2c2)b(a2+b2) \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 θ=arctan2(sinθ,cosθ)\theta = \arctan2 \left( \sin \theta , \cos \theta \right) in Arc Tangent 2.