articles:atan2

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
articles:atan2 [2021/06/22 11:47] Takashi Suehiroarticles:atan2 [2024/09/03 12:38] (現在) Takashi Suehiro
行 1: 行 1:
 ====== atan2 ====== ====== atan2 ======
  
-一般に正接関数($x=\mathrm{tan}(\theta$)の逆関数($\theta=\mathrm{tan}^{-1}(x)$)は値域を$(-\pi/2,\pi/2)$としている.+一般に正接関数($x=\mathrm{tan}\,\theta$)の逆関数($\theta=\mathrm{tan}^{-1}x$)は値域を$(-\pi/2,\pi/2)$としている.
  
 +[{{ articles:atan2.png?250| 図 atan2の役割 }}]
 たとえば, たとえば,
 $$ $$
行 12: 行 13:
 $$ $$
 である. である.
 +
 +しかし,これだとx,yの座標値でx軸からの回転角度を出すときに$\mathrm{tan}^{-1}(y/x)$としたのでは
 +図の斜線部(第2象限,第3象限)の角度を出すことが出来ない.
 +
 +これを可能にするのが$\mathrm{atan2}$関数であり,多くのプログラミング言語のライブラリに組み込まれている.
 +その定義は各象限,$\pi/2$,$-\pi/2$で場合分けされて以下のようになっている.
 +
 +$$
 +\theta =
 +\mathrm{atan2}(y,x)
 += \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}(y/x)+\pi & (x<0 \, y \ge 0) \\
 +\mathrm{unknown} & (x=0, \, y=0)
 +\end{array}
 +\right.
 +$$
 +pythonなど多くのプログラミング言語ライブラリでは$\mathrm{atan2}(0,0)$をunknownとせずに0.0としている.
 +
  
  
  • articles/atan2.1624330067.txt.gz
  • 最終更新: 2021/06/22 11:47
  • by Takashi Suehiro