Trigonometry

三角関数

It had never occurred to me until I started coding graphics, but trigonometry is actually extremely useful and I can’t live without it.

グラフィック系のコーディングを始めるまでは夢にも思いませんでしたが、三角関数は非常に便利で、それなしでは生きていけないほどです。

One of the most common uses of trigonometric functions in two-dimensional graphics is when you know the polar coordinates of an object, i.e., its angle and distance, and you want to convert them to x and y-coordinates. For example, if the enemy is at 45 degrees to the right and a distance of 100 from the spaceship, its xy-coordinates would be:

2次元のグラフィクスで最も使うのは対象物の極座標、つまり角度と距離が分かっている場合にそれをx座標とy座標に変換したい場合でしょう。例えば敵が宇宙船から右斜め45度、距離100の位置にいるとするとそのxy座標は下のようになります。

trig1.jpg

x = cos(45deg) * 100
y = sin(45deg) * 100

Trigonometric functions are easy to understand if you imagine a rotating line (or a ray) going through the center of a circle with a radius of 1. When the line is rotated by an angle θ, it intersects the circle at cos θ = x and sin θ = y. Using right triangles, we can also define the sine function as the ratio of the opposite side to the hypotenuse, and the cosine function as the ratio of the adjacent side to the hypotenuse.

三角関数は半径が1の円の中で線を角度θだけ回転させた時に、cos=x、sin=yと考えるとわかりやすいです。直角三角形を使って、サインは対辺(opposite)と斜辺(Hypotenuse)の比、コサインは隣辺(adjacent)と斜辺の比として定義することもできます。

trig2.jpg

${\displaystyle \sin A={\frac {\textrm {opposite}}{\textrm {hypotenuse}}}}$

${\displaystyle \cos A={\frac {\textrm {adjacent}}{\textrm {hypotenuse}}}}$