# Derivation of Coordinate System Transformation

When a point in $s$ coordinates should be interpreted in another $d$ coordinates, the transformation matrix between coordinate systems is needed. That is, the point in $s$ coordinates is not moved and is just reinterpreted from the point of view of the $d$ system. This kind of transformation can be everywhere such as OC-to-WC or WC-to-EC. Technically, a point in $s$ coordinates can be rewritten as follows. \begin{aligned} \left(\begin{array}{c} 0 \\ 0 \\ 0 \end{array}\right) + x_s \left(\begin{array}{c} 1 \\ 0 \\ 0 \end{array}\right) + y_s \left(\begin{array}{c} 0 \\ 1 \\ 0 \end{array}\right) + z_s \left(\begin{array}{c} 0 \\ 0 \\ 1 \end{array}\right) \end{aligned}

It implies that the point is located by moving $x_s$ towards $(1 \; 0 \; 0)^t$, $y_x$ towards $(0 \; 1 \; 0)^t$, and $z_s$ towards $(0 \; 0 \; 1)^t$ starting from the origin $(0 \; 0 \; 0)^t$. Let $(o_x \; o_y \; o_z)^t$ be the origin of $d$ coordinates. Then, the same point can be reinterpreted from the point of view of the $d$ coordinates. \begin{aligned} \left(\begin{array}{c} o_x \\ o_y \\ o_z \end{array}\right) + x_d \left(\begin{array}{c} u_x \\ u_y \\ u_z \end{array}\right) + y_d \left(\begin{array}{c} v_x \\ v_y \\ v_z \end{array}\right) + z_d \left(\begin{array}{c} n_x \\ n_y \\ n_z \end{array}\right) \end{aligned}

Considering that these two interpretations have the same meaning, \begin{aligned} \left(\begin{array}{c} x_s \\ y_s \\ z_s \end{array}\right) &= \left(\begin{array}{c} o_x \\ o_y \\ o_z \end{array}\right) + \left(\begin{array}{ccc} u_x & v_x & n_x \\ u_y & v_y & n_y \\ u_z & v_z & n_z \end{array}\right) \left(\begin{array}{c} x_d \\ y_d \\ z_d \end{array}\right) \\\\ \implies \left(\begin{array}{c} x_d \\ y_d \\ z_d \end{array}\right) &= \left(\begin{array}{ccc} u_x & v_x & n_x \\ u_y & v_y & n_y \\ u_z & v_z & n_z \end{array}\right)^{-1} \left(\left(\begin{array}{c} x_s \\ y_s \\ z_s \end{array}\right) - \left(\begin{array}{c} o_x \\ o_y \\ o_z \end{array}\right)\right) \\\\ &= \left(\begin{array}{ccc} u_x & u_y & u_z \\ v_x & v_y & v_z \\ n_x & n_y & n_z \end{array}\right) \left(\left(\begin{array}{c} x_s \\ y_s \\ z_s \end{array}\right) - \left(\begin{array}{c} o_x \\ o_y \\ o_z \end{array}\right)\right) \end{aligned}

The last part is because $u$, $v$, and $n$ column vectors compose the orthonormal matrix. Using a homogeneous system, this result can be rewritten about the transform matrix $M$. \begin{aligned} \left(\begin{array}{ccc} u_x & u_y & u_z \\ v_x & v_y & v_z \\ n_x & n_y & n_z \end{array}\right) \left(\begin{array}{c} o_x \\ o_y \\ o_z \end{array}\right) \equiv \left(\begin{array}{c} t_x \\ t_y \\ t_z \end{array}\right) &\implies \left(\begin{array}{c} x_d \\ y_d \\ z_d \\ 1 \end{array}\right) = \left(\begin{array}{cccc} u_x & u_y & u_z & -t_x \\ v_x & v_y & v_z & -t_y \\ n_x & n_y & n_z & -t_z \\ 0 & 0 & 0 & 1 \end{array}\right) \left(\begin{array}{c} x_s \\ y_s \\ z_s \\ 1 \end{array}\right) \\\\ \implies M = \left(\begin{array}{cccc} u_x & u_y & u_z & -t_x \\ v_x & v_y & v_z & -t_y \\ n_x & n_y & n_z & -t_z \\ 0 & 0 & 0 & 1 \end{array}\right) &= \left(\begin{array}{cccc} u_x & u_y & u_z & 0 \\ v_x & v_y & v_z & 0 \\ n_x & n_y & n_z & 0 \\ 0 & 0 & 0 & 1 \end{array}\right) \left(\begin{array}{cccc} 1 & 0 & 0 & -t_x \\ 0 & 1 & 0 & -t_y \\ 0 & 0 & 1 & -t_z \\ 0 & 0 & 0 & 1 \end{array}\right) \end{aligned}

Note that $u$, $v$, and $n$ are set as row vectors in $M$. More importantly, $M$ has an intuitive interpretation that it pulls the origin of $d$ coordinates to the origin of $s$ coordinates and then spins the three axes of $d$ coordinates to fit the axes of $s$ coordinates.

Sometimes, it is very confusing whether to set $u$, $v$, and $n$ as row vectors or column vectors. Here is a tip. $u$, $v$, and $n$ that are defined in $s$ coordinates should be the standard basis in $d$ coordinates. So, the following simple calculation may help to set directions. Let $M_{33}$ be the $3 \times 3$ submatrix of $M$. \begin{aligned} M_{33} \left(\begin{array}{c} u_x \\ u_y \\ u_z \end{array}\right) = \left(\begin{array}{c} 1 \\ 0 \\ 0 \end{array}\right), \qquad M_{33} \left(\begin{array}{c} v_x \\ v_y \\ v_z \end{array}\right) = \left(\begin{array}{c} 0 \\ 1 \\ 0 \end{array}\right), \qquad M_{33} \left(\begin{array}{c} n_x \\ n_y \\ n_z \end{array}\right) = \left(\begin{array}{c} 0 \\ 0 \\ 1 \end{array}\right) \end{aligned}

Note that $\lVert u \rVert = \lVert v \rVert = \lVert n \rVert = 1$ and $u \cdot v = v \cdot n = u \cdot n = 0$.