\[\mathbf{i} \mathbf{j}\]
is transformed onto the coorinate system \[\mathbf{i'} \mathbf{j'}\]
then \[\mathbf{i'} = \mathbf{i} \cdot \mathbf{i'} \mathbf{i} + \mathbf{j} \cdot \mathbf{i'} \mathbf{j}\]
\[\mathbf{j'} = \mathbf{i} \cdot \mathbf{j'} \mathbf{i} + \mathbf{j} \cdot \mathbf{j'} \mathbf{j}\]
The direction cosines are
\[\cos \alpha_{ii'} =\mathbf{i} \cdot \mathbf{i'}\]
\[\cos \alpha_{ij'} =\mathbf{i} \cdot \mathbf{j'}\]
\[\cos \alpha_{ji'} =\mathbf{j} \cdot \mathbf{i'}\]
\[\cos \alpha_{jj'} =\mathbf{j} \cdot \mathbf{j'}\]
We can write the transformation as
\[ \left( \begin{array}{c} \mathbf{i'} \\ \mathbf{j'} \end{array} \right) = \left( \begin{array}{cc} \cos \alpha_{ii'} & \cos \alpha_{ij'} \\ \cos \alpha_{ji'} & \cos \alpha_{jj'} \end{array} \right) \left( \begin{array}{c} \mathbf{i} \\ \mathbf{j} \end{array} \right)\]
Similarly in three dimensions
\[ \left( \begin{array}{c} \mathbf{i'} \\ \mathbf{j'} \\ \mathbf{k'} \end{array} \right) = \left( \begin{array}{ccc} \cos \alpha_{ii'} & \cos \alpha_{ij'} & \cos \alpha_{ik'} \\ \cos \alpha_{ji'} & \cos \alpha_{jj'} & \cos \alpha_{jk'} \\ \cos \alpha_{ki'} & \cos \alpha_{kj'} & \cos \alpha_{kk'}\end{array} \right) \left( \begin{array}{c} \mathbf{i} \\ \mathbf{j} \\ \mathbf{k} \end{array} \right)\]