1-5. 一次独立

一次独立

一次独立の例

\boldsymbol{a_1} = \begin{pmatrix} 1 \\ 0 \end{pmatrix},\ \boldsymbol{a_2} = \begin{pmatrix} 0 \\ 1 \end{pmatrix} は一次独立である。

また、これら2つのベクトルを 45\degree 回転させた \boldsymbol{a_1} = \begin{pmatrix} 1 \\ 1 \end{pmatrix},\ \boldsymbol{a_2} = \begin{pmatrix} 1 \\ -1 \end{pmatrix} も一次独立である。簡単に言えば、あるベクトル(点)を作る c_1\boldsymbol{a}_1 + c_2\boldsymbol{a}_2 + \cdots + c_n\boldsymbol{a}_n の組み合わせがひとつしかないものであり、単位ベクトルに限られるものではない。

線型写像

例

平面上の座標 \boldsymbol{a} = (a_1, a_2) を原点中心に \theta だけ回転させる写像 f について、原点 \boldsymbol{o} のほか \boldsymbol{a},\ \boldsymbol{b},\ \boldsymbol{a} + \boldsymbol{b} を頂点とする平行四辺形を考え、これを回転させると f(\boldsymbol{a} + \boldsymbol{b}) = f(\boldsymbol{a}) + f(\boldsymbol{b}) であることが直感的にわかる。また、回転させてもベクトルの大きさ(距離)は変わらないので、f(c\boldsymbol{a}) = cf(\boldsymbol{a}) となり f は線形写像となる。

\boldsymbol{a} の大きさを r として \boldsymbol{a} = (r \cos \phi, r \sin \phi)、f の表現行列を A = \begin{pmatrix} v & w \\ x & y \end{pmatrix} とおくと、

\begin{pmatrix} v & w \\ x & y \end{pmatrix} \begin{pmatrix} r \cos \phi \\ r \sin \phi \end{pmatrix} = \begin{pmatrix} r \cos (\phi + \theta) \\ r \sin (\phi + \theta) \end{pmatrix}

が成り立つ必要がある。v, w, x, y の値を求めるために、加法定理を思い出してみる。

\begin{aligned} \sin (\alpha \pm \beta) = \sin(\alpha) \cos(\beta) \pm \cos(\alpha) \sin(\beta) \\ \cos (\alpha \pm \beta) = \cos(\alpha) \cos(\beta) \mp \sin(\alpha) \sin(\beta) \end{aligned}

であるので、

\begin{aligned} \begin{pmatrix} v & w \\ x & y \end{pmatrix} \begin{pmatrix} r \cos \phi \\ r \sin \phi \end{pmatrix} = \begin{pmatrix} v r \cos \phi + w r \sin \phi \\ x r \cos \phi + y r \sin \phi \end{pmatrix} = \begin{pmatrix} r \cos (\phi + \theta) \\ r \sin (\phi + \theta) \end{pmatrix} \end{aligned}

となる。両辺を見比べることで、v = \cos\theta,\ w = -\sin\theta,\ x = \sin\theta,\ y = \cos\theta であることがわかるので、

\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}$$ となる。 # 線形写像ってどこで使われているの? コンピュータサイエンスでもよく使われていて、色変換ではR, G, Bの画素値を操作して明るくしたりコントラストを強調したり、色相を回転させたり(!?)するときにも使われている。 ## 並行移動 座標 $(x, y)$ にある点を $(x + x_t,\ y + y_t)$ に移動させることを考える。2x2 の行列による変換は視察により、

\begin{pmatrix} \frac{x + x_t}{x} & 0 \ 0 & \frac{y + y_t}{y} \end{pmatrix} \begin{pmatrix} \vphantom{\frac{x + x_t}{x}} x \ \vphantom{\frac{y + y_t}{y}} y \end{pmatrix} = \begin{pmatrix} \vphantom{\frac{x + x_t}{x}} x + x_t \ \vphantom{\frac{y + y_t}{y}} y + y_t \end{pmatrix}

が考えられるが、これは $x \ne 0$ のときに限られるので汎用性がない。そこで 3x3 を考えると

\begin{pmatrix} 1 & 0 & x_t \ 0 & 1 & y_t \ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x \ y \ 1 \end{pmatrix} = \begin{pmatrix} x + x_t \ y + y_t \ 1 \end{pmatrix}

となるので、1次元多くなるがうまく辻褄を合わせることができる。もちろん3次元の場合には同様に 4x4 行列となる。 ## なにが嬉しいのか? 行列による変換は複数の値を同時に計算できることが強みで、ここで複数の点 $(x_0, y_0), \cdots, (x_n, y_n)$ があったときに、

\begin{pmatrix} 1 & 0 & x_t \ 0 & 1 & y_t \ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix}
x_0 & x_1 & \cdots & x_n \
y_0 & y_1 & \cdots & y_n \
1 & 1 & \cdots & 1 \end{pmatrix}
= \begin{pmatrix}
x_0 + x_t & x_1 + x_t & \cdots & x_n + x_t \
y_0 + y_t & y_1 + y_t & \cdots & y_n + y_t \
1 & 1 & \cdots & 1
\end{pmatrix}

とできる。さらに内積の性質から加算、減算、乗算しか出てこないので、計算を最適化しやすい。 ## 色相回転 次の線形写像で $(R, G, B)$ の色相を $H$ 度回転できる。

\begin{pmatrix}
0.213 + 0.787\cos(H) - 0.213\sin(H) & 0.715 - 0.715\cos(H) - 0.715\sin(H) & 0.072 - 0.072\cos(H) + 0.928\sin(H) \
0.213 - 0.213\cos(H) + 0.143\sin(H) & 0.715 + 0.285\cos(H) + 0.140\sin(H) & 0.072 - 0.072\cos(H) - 0.283\sin(H) \
0.213 - 0.213\cos(H) - 0.787\sin(H) & 0.715 - 0.715\cos(H) + 0.715\sin(H) & 0.072 + 0.928\cos(H) + 0.072\sin(H)
\end{pmatrix}
\begin{pmatrix} R \ G \ B \end{pmatrix}

この式はWebKitの `filter: hue-rotate()` の実装 [ColorMatrix.h](https://github.com/WebKit/WebKit/blob/bb5b3e0e809d3a5eec63d6016a1e89bfd027f9d4/Source/WebCore/platform/graphics/ColorMatrix.h) に採用されている。ちなみにHSL(HSV)空間で色相(H)を回転させた結果と、線形写像した結果は色味が異なる点に注意。つまり、正確に色相を回転させているわけではないので、 $$\textrm{hue-rotate}(x,\ 0\degree) = \textrm{hue-rotate}(x,\ 360\degree)$$ とはならず、色味も少し異なる。