Reflect a point across a line using affine transform I'm trying to reflect a point (6,12) across the line y=7 using an affine transformation. Logically, the line y=7 should be halfway the Y coordinate 12 and the Y coordinate of the answer, so (12+Y)/2=7, or 12+Y=14, or Y=2, so the answer is (6,2).
Wikipedia has examples of affine transformations at https://en.wikipedia.org/wiki/Affine_transformation#In_plane_geometry.
The approach I'm trying is 'translate Y -7', then 'reflect about X axis', then 'translate Y +7', leading me to believe I need these three transforms:
$$
\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & -7 \\
0 & 0 & 1 \\
\end{bmatrix}
.
\begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & 0 \\
0 & 0 & 1 \\
\end{bmatrix}
.
\begin{bmatrix}
1 & 0 & 0 \\
0 & 1 & 7 \\
0 & 0 & 1 \\
\end{bmatrix}
=
\begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & -14 \\
0 & 0 & 1 \\
\end{bmatrix}
$$
But if I then multiply this with my point (6,12) I get the wrong answer:
$$
\begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & -14 \\
0 & 0 & 1 \\
\end{bmatrix}
.
\begin{bmatrix}
6 \\
12 \\
1 \\
\end{bmatrix}
=
\begin{bmatrix}
6 \\
-26 \\
1 \\
\end{bmatrix}
$$
And if I switch around the two translation steps, the sign of the translation changes and I do get the correct answer:
$$
\begin{bmatrix}
1 & 0 & 0 \\
0 & -1 & 14 \\
0 & 0 & 1 \\
\end{bmatrix}
.
\begin{bmatrix}
6 \\
12 \\
1 \\
\end{bmatrix}
=
\begin{bmatrix}
6 \\
2 \\
1 \\
\end{bmatrix}
$$
This gives the correct answer, but now I don't understand why this works, geometrically speaking! Shouldn't the positive Y transform now translate the point (2,12) to (2,19), then reflect that to (2,-19) and translate that to (2,-12)?
 A: To reflect about the plane $\mathbf{n} (\mathbf{r} - \mathbf{r_0} ) = 0 $, ($\mathbf{n}$ is a unit vector), the affine transformation is
$ T(\mathbf{p}) = \mathbf{r_0} + A (\mathbf{p} - \mathbf{r_0} ) $
where
$T = \mathbf{I} - 2 {\mathbf{n}\mathbf{n}}^T $
In this case, the plane is $y = 7$, so $\mathbf{n} = \begin{bmatrix} 0 \\ 1 \\ 0 \end{bmatrix}$ and $\mathbf{r_0} = \begin{bmatrix} 0 \\ 7 \\ 0 \end{bmatrix} $
Matrix $A$ is
$A = \begin{bmatrix} 1 && 0 && 0 \\ 0 && 1 && 0 \\ 0 && 0 && 1 \end{bmatrix} - 2 \begin{bmatrix} 0 && 0 && 0 \\ 0 && 1 && 0 \\ 0 && 0 && 0 \end{bmatrix} = \begin{bmatrix} 1 && 0 && 0 \\ 0 && -1 && 0 \\ 0 && 0 && 1 \end{bmatrix}$
Using the formula for reflection,
$T\left(\begin{bmatrix} 6 \\ 12 \\ 0 \end{bmatrix} \right) = \begin{bmatrix} 0 \\ 7 \\ 0 \end{bmatrix} + \begin{bmatrix} 1 && 0 && 0 \\ 0 && -1 && 0 \\ 0 && 0 && 1 \end{bmatrix} \begin{bmatrix} 6 - 0\\ 12 - 7 \\ 0 - 0 \end{bmatrix} = \begin{bmatrix} 6 \\ 2\\ 0 \end{bmatrix} $
Note that I am using the $3D$ coordinates not homogeneous coordinates in $2D$.
