三角関数#
三角比#
直角三角形は、内角\(\theta\)の値を固定するとすべて相似な形となるため、\(x/r\)や\(y/r\)などの辺の長さ同士の比は一定になる。
この値を三角比と呼び、角度\(\theta\)の値によって決まるものとなる。
三角関数#
三角比の定義では、直角三角形の内角となりうる\(0^\circ\)から\(90^\circ\)の間の値しかとれないが、それ以外の値もとれるように定義を拡張したものが三角関数である。
単位円(半径\(r=1\)の円)上において、\(\sin \theta = \frac{y}{1} = y, \cos \theta = \frac{x}{1} = x\)となり扱いやすい。
これを利用して、半径1、中心が原点\(O\)の円(単位円)の円周上の点、\(x\)軸の正の向きからの角度が\(\theta\)の点の\(y\)座標を\(\sin \theta\)、\(x\)座標を\(\cos \theta\)と定義する。
逆三角関数#
三角関数の逆関数のことを逆三角関数という。
例:内積から角度を取り出す#
で、ここで\(\theta\)はラジアンであり、コサイン類似度\(\cos \theta = 0\)のときは\(\theta = \arccos \theta= \frac{\pi}{2} \approx 1.571\)
ラジアンを度(degree)に戻すには\(degree = \theta \times (180 / \pi)\)
Note
内積やコサイン類似度との関係
2つのベクトル\(a, b\)のなす角度を\(\theta\)とすると、内積\(\boldsymbol{a} \cdot \boldsymbol{b}\)は
と定義される。
単位円上の2つの矢印ならどちらもノルムは1なので内積が\(\cos \theta\)を表す。
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from current font.
plt.tight_layout()
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 12398 (\N{HIRAGANA LETTER NO}) missing from current font.
plt.tight_layout()
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 30456 (\N{CJK UNIFIED IDEOGRAPH-76F8}) missing from current font.
plt.tight_layout()
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 38306 (\N{CJK UNIFIED IDEOGRAPH-95A2}) missing from current font.
plt.tight_layout()
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 28961 (\N{CJK UNIFIED IDEOGRAPH-7121}) missing from current font.
plt.tight_layout()
/tmp/ipykernel_6185/299106162.py:81: UserWarning: Glyph 36000 (\N{CJK UNIFIED IDEOGRAPH-8CA0}) missing from current font.
plt.tight_layout()
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 12398 (\N{HIRAGANA LETTER NO}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 30456 (\N{CJK UNIFIED IDEOGRAPH-76F8}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 38306 (\N{CJK UNIFIED IDEOGRAPH-95A2}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 28961 (\N{CJK UNIFIED IDEOGRAPH-7121}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
/home/runner/work/notes/notes/.venv/lib/python3.10/site-packages/IPython/core/pylabtools.py:170: UserWarning: Glyph 36000 (\N{CJK UNIFIED IDEOGRAPH-8CA0}) missing from current font.
fig.canvas.print_figure(bytes_io, **kw)
bからaへ垂線をたらして射影したものの長さは\(||b|| \sin \theta\)となる。これは単位円における\(y = r \sin \theta\)に相当する(ノルム\(||b||\)はベクトルの長さのため)
同様に\(x = r \cos \theta\)から\(y = ||b|| \cos \theta\)となる
はずだが…?
cos_theta = (a @ b) / (np.linalg.norm(a) * np.linalg.norm(b)) # cos θ
b_length = np.linalg.norm(b) * cos_theta # |b| cos θ
print(b_length, np.linalg.norm(b_)) ## 一致しない
1.7888543819998315 2.23606797749979
cos_theta = (a @ b) / (np.linalg.norm(a) * np.linalg.norm(b)) # cos θ
theta = np.arccos(cos_theta)
b_length = np.linalg.norm(b) * np.sin(theta) # |b| sin θ
print(b_length, np.linalg.norm(b - b_)) ## 一致しない
1.3416407864998743 1.4142135623730951
三角関数の基本的性質#
性質1
一般に \(f(-x)=-f(x)\) となる関数を 奇関数、 \(f(-x)=f(x)\) となる関数を 偶関数 という。
\(\sin x, \tan x\) は奇関数, \(\cos x\) は偶関数である
性質2(相互関係)
三平方の定理より\(x^2 + y^2 = r^2\)なので
性質3 (加法定理)
性質4(2倍角の公式)