Reflection across a line?

You can have (far) more elegant derivations of the matrix when you have some theory available. The low-tech way using barely more than matrix multiplication would be:

The line $y = mx$ is parametrised by $t \cdot \begin{pmatrix}1\\m\end{pmatrix}$. The line orthogonal to it is parametrised by $r \cdot \begin{pmatrix}-m\\1\end{pmatrix}$. The line $y = mx$ shall be fixed, the line orthogonal to it shall be reflected, so you want a matrix $R$ with

$$R \begin{pmatrix}1 & -m\\ m & 1\end{pmatrix} = \begin{pmatrix}1 & m\\ m & -1\end{pmatrix},$$

and that means

$$\begin{align} R &= \begin{pmatrix}1 & m\\m&-1\end{pmatrix} \begin{pmatrix}1&-m\\m&1\end{pmatrix}^{-1}\\ & = \begin{pmatrix}1&m\\m&-1\end{pmatrix}\cdot \frac{1}{1+m^2}\begin{pmatrix}1&m\\-m&1\end{pmatrix}\\ &= \frac{1}{1+m^2} \begin{pmatrix}1 - m^2 & 2m\\2m &m^2-1\end{pmatrix}. \end{align}$$


Another way. To reflect along a line that forms an angle $\theta$ with the horizontal axis is equivalent to:

  • rotate an angle $-\theta$ (to make the line horizontal)
  • invert the $y$ coordinate
  • rotate $\theta$ back.

Further, $y=mx$ implies $\tan \theta = m$, and $1+m^2 = \frac{1}{\cos^2\theta}$ .

Then, assumming you know about rotation matrices, you can write

$$\begin{align}T&=\begin{pmatrix}\cos \theta & -\sin \theta\\ \sin \theta & \cos \theta\end{pmatrix} \begin{pmatrix}1&0\\ 0 & -1\end{pmatrix} \begin{pmatrix}\cos \theta & \sin \theta\\ -\sin \theta & \cos \theta\end{pmatrix} \\ &= \begin{pmatrix}\cos \theta & -\sin \theta\\ \sin \theta & \cos \theta\end{pmatrix} \begin{pmatrix}\cos \theta & \sin \theta\\ \sin \theta & -\cos \theta\end{pmatrix} \\ &= \cos^2 \theta \begin{pmatrix}1 & -\tan \theta\\ \tan \theta & 1\end{pmatrix} \begin{pmatrix}1 & \tan \theta\\ \tan\theta & -1\end{pmatrix} \\ &= \frac{1}{1 + m^2} \begin{pmatrix}1 & -m\\ m & 1\end{pmatrix} \begin{pmatrix}1 & m\\ m & -1\end{pmatrix} \\ &=\frac{1}{1 + m^2}\begin{pmatrix}1-m^2&2m\\2m&m^2-1\end{pmatrix}\end{align}$$


Vectors on the line obey the equation

$$y - mx = 0$$

Let $e_x, e_y$ be Cartesian basis vectors associated with the $x, y$ coordinates, respectively. The above equation implies that any vector $r = x e_x + y e_y$ that lies on the line must satisfy

$$r \cdot n = 0, \quad n = -m e_x + e_y$$

The vector $n$ is the normal vector to the line, perpendicular to the line. The associated unit normal is $\hat n = n/\sqrt{1+m^2}$.

Any vector $a$ can be broken down into a component that is parallel to the line and a component that is perpendicular. This is written $a = a_\parallel + a_\perp$. When the vector is reflected by a reflection map $\underline N$, the perpendicular component changes sign; the parallel component does not. That is,

$$\underline N(a) = a_\parallel - a_\perp = a - 2 a_\perp$$

The perpendicular component $a_\perp$ is given by

$$a_\perp = (a \cdot \hat n) \hat n$$

where $a = a^x e_x + a^y e_y$. You should be able to recognize that this is merely a projection map onto the vector $\hat n$.

Thus, the reflection map is given as

$$\underline N(a) = \underline I(a) - 2(a \cdot \hat n) \hat n$$

where $\underline I$ is the identity map.

From here, one need only evaluate this in terms of basis vectors to find the matrix components.

$$\underline N(e_x) = e_x - 2 (e_x \cdot \hat n) \hat n = e_x - \frac{2(-m)(-m e_x + e_y)}{1 + m^2} = \frac{(1-m^2)e_x + 2m e_y}{1+m^2}$$

and

$$\underline N(e_y) = e_y - 2 (e_y \cdot \hat n) \hat n = e_y - \frac{2(1)(-me_x + e_y)}{1+m^2} = \frac{2m e_x + (m^2 - 1)e_y}{1+m^2}$$

Both of these are columns of the associated matrix representation.