Finding the reflection that reflects in an arbitrary line y=mx+b 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
 A: Geometrical Approach:
In general (see derivation), when a given point $P(x_0, y_0)$ is reflected about the line: $y=mx+c$ then the co-ordinates of the point of reflection $P'(x', \ y')$ are calculated by the following formula 
$$\color{blue}{(x', y')\equiv \left(\frac{(1-m^2)x_0+2m(y_0-c)}{1+m^2}, \frac{2mx_0-(1-m^2)y_0+2c}{1+m^2}\right)}$$ 
now, the point of reflection of $(0, 8)$ about the given line: $y=-\frac{1}{2}x+2$ is calculated  by setting the corresponding values, $x_0=0, \ y_0=8, \ m=-\frac{1}{2}$ & $c=2$ as follows$$\left(\frac{(1-\left(-\frac{1}{2}\right)^2)(0)+2\left(-\frac{1}{2}\right)(8-2)}{1+\left(-\frac{1}{2}\right)^2}, \frac{2\left(-\frac{1}{2}\right)(0)-(1-\left(-\frac{1}{2}\right)^2)(8)+2(2)}{1+\left(-\frac{1}{2}\right)^2}\right)\equiv\left(\frac{-24}{5}, \frac{-8}{5}\right)\equiv \color{red}{(-4.8, \ -1.6)}$$ 
So the answer $[-4.8, -1.6]$ according to Geogebra is correct. 
A: One way to do this is as a composition of three transformations:


*

*Translate by $(0,-b)$ so that the line $y=mx+b$ maps to $y=mx$.

*Reflect through the line $y=mx$ using the known formula.

*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.
