Arc Tangent 2arctan2:(R2∖{(0,0)})→R is defined as follows.
arctan2:(rsinθ,rcosθ)↦θ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 cossin, even when the position information rcos, rsin 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 θ=arctan2(y,x) in C language and MATLAB, but in some cases, it is θ=arctan2(x,y). If it follows the sine-cosine order, arctan2(sin,cos) feels natural, and if it follows the x-y order, arctan2(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
If the linear combination of trigonometric functions is as c∈R, the angleθ is as follows.
cosθ=sinθ=θ=a2+b2ac±b2(a2+b2−c2)b(a2+b2)b2c∓ab2(a2+b2−c2)arctan2(sinθ,cosθ)
Especially when c=0, the following simpler form can be used.
cosθ=sinθ=θ=±a2+b2b2∓baa2+b2b2arctan2(sinθ,cosθ)
Quadratic Formula: For the quadratic equation ax2+bx+c=0 (where, a=0)
x=2a−b±b2−4ac
Since sinθ=1−cos2θ,
⟹⟹⟹⟹acosθ+bsinθ=cacosθ−c=−bsinθa2cos2θ−2accosθ+c2=b2(1−cos2θ)a2cos2θ−2accosθ+c2=b2(1−cos2θ)(a2+b2)cos2θ−2accosθ+(c2−b2)=0
following the quadratic formula when the coefficient of the first term is twice,
cosθ==a2+b2ac±a2c2−(a2+b2)(c2−b2)a2+b2ac±−b2c2+a2b2+b4
Meanwhile, since sinθ=bc−acosθ,
sinθ=====bc−acosθbc−aa2+b2ac±b2(a2+b2−c2)bc−b(a2+b2)a2c±ab2(a2+b2−c2)bc(a2+b2)−b(a2+b2)a2c±ab2(a2+b2−c2)−b(a2+b2)b2c±ab2(a2+b2−c2)
Now that we know the sine and cosine, we get the desired θ=arctan2(sinθ,cosθ) in Arc Tangent 2.