文書の過去の版を表示しています。
atan2
一般に正接関数($x=\mathrm{tan}(\theta$)の逆関数($\theta=\mathrm{tan}^{-1}(x)$)は値域を$(-\pi/2,\pi/2)$としている.
たとえば, $$ \mathrm{tan}(\pi/4)=1 $$ であり, $$ \mathrm{tan}^{-1}(1)=\pi/4 $$ である.
$$ \theta = \mathrm{atan2}(x,y) = \left\{ \begin{array}{cc} \mathrm{tan}^{-1}(y/x)-\pi & (x<0, \, y<0) \\ -\pi/2 & (x=0,\, y<0) \\ \mathrm{tan}^{-1}(y/x) & (x>0) \\ \pi/2 & (x=0,\, y>0) \\ \mathrm{tan}^{-1}(x/y)+\pi & (x<0 \, y \ge 0) \\ \mathrm{unknown} & (x=0, \, y=0) \end{array} \right. $$ pythonなど多くのプログラミング言語ライブラリでは$\mathrm{atan2}(0,0)$をunknownとせずに0.0としている.
