Atan2 function
Colin Cheng ( 鄭聖文 )
Shengwen1997.tw@gmail.com
Brief explanation about the difference
between atan and atan2.
Just a normal example
x
y
1
1
θ
(1,1)=[√2, π
4
]
θ=atan(
y
x
)
θ=atan(
1
1
)= π
4
Next example
1
-1
θ
θ=atan(
y
x
)
θ=atan(
−1
1
)=atan(−1)=−π
4
What if...
1
-1
θ
θ=atan(
y
x
)
θ=atan(
−1
1
)=atan(−1)=−π
4
θ=atan(
1
−1
)=atan(−1)=−π
4
1
-1
Avoid the preoblem
by using atan2!
Atan2
atan2( y , x)=
atan( y/x) for x>0
atan( y/x)+π for x<0, y≥0
atan( y/x)−π for x<0, y<0
π/2 for x=0 , y>0
−π/2 for x=0, y<0
undefined for x=0, y=0
Type “man atan” and “man atan2” under
Linux to get the detailed description.

atan2 brief explain