Reflect a point across a line using affine transform

affine-geometrylinear algebra

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)?

Best Answer

The approach is correct but the matrix doesn't reflect what you intended: it's in the reverse order. Suppose you have 3 transforms $A$, $B$, $C$, applied in that order. The result of first transformation on a vector $p$ is $q=Ap$, followed by the next transformation $r=Bq$ and finally $s=Cr$. If you substitute the intermediate results one by one you get $s=CBAp$.

Related Question