Derive a transformation matrix that mirrors the image over a line passing through the origin with angle $\phi$ to the $x$-axis. Question: Using homogeneous coordinates, derive a $3$x$3$ transformation matrix $M$ that mirrors an image over a line passing through the origin, with angle $\phi$ to the $x$-axis.
Comment: This is from an old exam in computer graphics. I don't remember how we did this back in linear algebra so I'd be grateful if someone could show me the steps. If you don't know what "homogeneous coordinates" means, pay no attention to it, a $2$x$2$ transformation matrix without homogenous coordinates would suffice and I can do the rest.
 A: One way to do this is to think about rotating the plane $-\phi$ degrees, so that the desired line of reflection is now the $x$-axis, then reflect over the $x$-axis, then rotate back by $\phi$ degrees.
How do we do it?  Recall the "rotation by $\phi$" matrix \begin{equation*}R_{\phi} = \begin{pmatrix} \cos(\phi) & -\sin(\phi) \\ \sin(\phi) & \cos(\phi)\end{pmatrix},\end{equation*}
and the "reflect over the $x$-axis" matrix
\begin{equation*} Refl_x = \begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix}.\end{equation*}
Then the "reflect across angle $\phi$" matrix $Refl_{\phi}$ is calculated as we described above:
\begin{eqnarray*}Refl_{\phi} &=& R_{\phi}\cdot Refl_x \cdot R_{-\phi} \\
&=& \begin{pmatrix} \cos(\phi) & -\sin(\phi) \\ \sin(\phi) & \cos(\phi)\end{pmatrix}\begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix}\begin{pmatrix} \cos(-\phi) & -\sin(-\phi) \\ \sin(-\phi) & \cos(-\phi)\end{pmatrix}\\
&=&\begin{pmatrix} \cos(\phi) & -\sin(\phi) \\ \sin(\phi) & \cos(\phi)\end{pmatrix}\begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix}\begin{pmatrix} \cos(\phi) & \sin(\phi) \\ -\sin(\phi) & \cos(\phi)\end{pmatrix} \\
&=&\begin{pmatrix}\cos^2(\phi)-\sin^2(\phi) & 2\cos(\phi)\sin(\phi) \\ 2\cos(\phi)\sin(\phi)& \sin^2(\phi)-\cos^2(\phi)\end{pmatrix} \\
&=&\begin{pmatrix}\cos(2\phi) & \sin(2\phi) \\ \sin(2\phi) & -\cos(2\phi)\end{pmatrix}\end{eqnarray*}
A: If vector $A$ is reflected across vector $B$ to create vector $C$,


*

*The  midpoint of $A$ and $C$ is along $B$:
$C + (A - C)/2 \in kB$, so $A + C \in kB$

*Length is preserved: $|A| = |C|$


Your $B$ vector is $\begin{bmatrix} \cos(\phi) \\ \sin(\phi)\end{bmatrix}$
First consider the x-axis unit: $e_1 = \begin{bmatrix} 1 \\ 0 \end{bmatrix}$ translates to $f(e_1) =  \begin{bmatrix} a \\ b \end{bmatrix}$:
$$\begin{bmatrix} 1 \\ 0 \end{bmatrix} + \begin{bmatrix} a \\ b \end{bmatrix} = k\begin{bmatrix} \cos(\phi) \\ \sin(\phi)\end{bmatrix}$$
$$\begin{cases} a + 1 = k \cos(\phi) \\
                b = k \sin(\phi) \\
                a^2 + b^2 = 1 \quad \text{(because length is preserved)}
\end{cases}$$
$$\downarrow$$
$$\begin{cases} k = 2\cos(\phi) \\
 a = 2\cos(\phi)^2 - 1 \\
 b = 2\cos(\phi)\sin(\phi)
\end{cases}$$
Same for the y-unit $e_2 = \begin{bmatrix} 0 \\ 1 \end{bmatrix}$ translates to $f(e_2) =  \begin{bmatrix} c \\ d \end{bmatrix}$:
$$\begin{bmatrix} 0 \\ 1 \end{bmatrix} + \begin{bmatrix} c \\ d \end{bmatrix} = k\begin{bmatrix} \cos(\phi) \\ \sin(\phi)\end{bmatrix}$$
$$\begin{cases} c = k \cos(\phi) \\
                d + 1 = k \sin(\phi) \\
                c^2 + d^2 = 1 \quad \text{(again because length is preserved)}
\end{cases}$$
$$\downarrow$$
$$\begin{cases} k = 2\sin(\phi) \\
 c = 2\cos(\phi)\sin(\phi) \\
 d = 2\sin(\phi)^2 - 1
\end{cases}$$
Since we know that $f(v) = f(xe_1 + ye_2) = xf(e_1) + yf(e_2)$, it follows:
$$\begin{align}
f\left(\begin{bmatrix} x \\ y \end{bmatrix}\right) &= \begin{bmatrix} 2\cos(\phi)^2 - 1 & 2\cos(\phi)\sin(\phi) \\ 2\cos(\phi)\sin(\phi) & 2\sin(\phi)^2 - 1\end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \\
&= \begin{bmatrix} \cos(2\phi) & \sin(2\phi) \\ \sin(2\phi) & -\cos(2\phi)\end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \\
\end{align}$$
