[Math] Finding the reflection that reflects in an arbitrary line y=mx+b

linear algebramatrices

How can I find the reflection that reflects in an arbitrary line, $y=mx+b$

I've examples where it's $y=mx$ without taking in the factor of $b$

But I want to know how you can take in the factor of $b$

And after searching through for some results, I came to this matrix which i think can solve my problems. But it doesn't seem to work.

$$
\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} =
\begin{bmatrix}
\frac{1-m^2}{1 + m^2} & \frac{-2m}{1 + m^2} & \frac{-2mb}{1 + m^2} \\
\frac{-2m}{1 + m^2} & \frac{m^2-1}{1 + m^2} & \frac{2b}{1 + m^2} \\
0 & 0 & 1
\end{bmatrix}
\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}.
$$

The example I tried to use using this matrix is
the point $(0,8)$ reflected on $y=-\frac{1}{2}x+2$.
The result I get from that matrix is $[6.4,-0.6,0]$.
The actual answer should be $[-4.8, -1.6]$ , according to Geogebra

Best Answer

One way to do this is as a composition of three transformations:

  1. Translate by $(0,-b)$ so that the line $y=mx+b$ maps to $y=mx$.
  2. Reflect through the line $y=mx$ using the known formula.
  3. Translate by $(0,b)$ to undo the earlier translation.

The translation matrices are, respectively, $$ \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & -b \\ 0 & 0 & 1 \end{pmatrix} \quad\text{and}\quad \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & b \\ 0 & 0 & 1 \end{pmatrix} $$ and the matrix of the reflection about $y=mx$ is $$ \frac{1}{1 + m^2} \begin{pmatrix} 1-m^2 & 2m & 0 \\ 2m & m^2-1 & 0 \\ 0 & 0 & 1 + m^2 \end{pmatrix}. $$

Applying these in the correct sequence, the transformation is $$ \frac{1}{1 + m^2} \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & b \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 1-m^2 & 2m & 0 \\ 2m & m^2-1 & 0 \\ 0 & 0 & 1 + m^2 \end{pmatrix} \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & -b \\ 0 & 0 & 1 \end{pmatrix} $$ $$ = \frac{1}{1 + m^2} \begin{pmatrix} 1-m^2 & 2m & -2mb \\ 2m & m^2-1 & 2b \\ 0 & 0 & 1 + m^2 \end{pmatrix}. $$

This is much like the matrix you found, but the entries that you set to $\frac{-2m}{1+m^2}$ are instead $\frac{2m}{1+m^2}$.

Setting $m=-\frac12$, $b=2$, the matrix is $$ \frac45 \begin{pmatrix} \frac34 & -1 & 2 \\ -1 & -\frac34 & 4 \\ 0 & 0 & \frac54 \end{pmatrix} = \begin{pmatrix} 0.6 & -0.8 & 1.6 \\ -0.8 & -0.6 & 3.2 \\ 0 & 0 & 1 \end{pmatrix} $$ and applying this to the point $(0,8)$ we have $$ \begin{pmatrix} 0.6 & -0.8 & 1.6 \\ -0.8 & -0.6 & 3.2 \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} 0 \\ 8 \\ 1 \end{pmatrix} = \begin{pmatrix} -4.8 \\ -1.6 \\ 1 \end{pmatrix}, $$ that is, the reflection of $(0,8)$ is $(-4.8, -1.6)$, so the matrix multiplication has the desired effect.