How do I get a matrix from a reflection? I have the following question:
$S : \Bbb{R}^2 \to \Bbb{R}^2$ is the reflection at the line $y = 2$.
How do I get the matrix of $S$ at homogeneous coordinates? And to be honest, I don't get this question at all. I have no idea of what I am supposed to do here or how. I do really want to learn this and hope that someone can explain it to me.
I appreciate your help.
 A: The reflection S is an affine transformation of the plane $\mathbb{R}^2$. An affine transformation is simply a map sending a vector $\vec{a}$ to the vector $S(\vec{a}) = T(\vec{a}) + \vec{k}$ where $T:\mathbb{R}^2\rightarrow\mathbb{R}^2$ is a linear transformation and $\vec{k}\in\mathbb{R}^2$ is some constant translation vector.
In homogeneous co-ordinates, we can represent an affine transformation as a linear transformation in the following way. If $A$ is the matrix of the linear transformation $T$, then we have the correspondence
$$A\vec{a} + \vec{k} \hspace{10pt}\leftrightarrow\hspace{10pt} \left[\begin{array}{c|c}A &\vec{k}\\\hline\begin{array}{cc}0&0\end{array}&1\end{array}\right]\left[\begin{array}{c}\vec{a}\\1\end{array}\right]$$
(where the vector on the right is obtained by simply carrying out the matrix multiplication).
Thus in the case of the reflection across the line $y = 2$, we see that $$S\left(\left[\begin{array}{c}x\\y\end{array}\right]\right) = \left[\begin{array}{c}x\\4-y\end{array}\right] = \left[\begin{array}{c}x\\-y\end{array}\right] + \left[\begin{array}{c}0\\4\end{array}\right]$$
So we want to find a matrix $A = \left[\begin{array}{cc}a_1& a_2\\a_3 & a_4\end{array}\right]$ such that $\left[\begin{array}{ccc}a_1 & a_2 & 0\\a_3 & a_4 & 4\\0 & 0 & 1\end{array}\right]\left[\begin{array}{c}x\\y\\1\end{array}\right] = \left[\begin{array}{c}x\\4-y\\1\end{array}\right]$.
i.e. we want, in particular, to have $A$ such that $\left[\begin{array}{cc}a_1 & a_2\\a_3 &a_4\end{array}\right]\left[\begin{array}{c}x\\y\end{array}\right] = \left[\begin{array}{c}x\\-y\end{array}\right]$. From here it is not hard to see that $A$ must be the matrix $\left[\begin{array}{cc}1 & 0\\0 & -1\end{array}\right]$ and thus the matrix of $S$ in homogeneous coordinates is:
$$\left[\begin{array}{ccc}1 & 0 & 0\\0 & -1 & 4\\0 & 0 & 1\end{array}\right]$$
A: $\renewcommand{\vec}[1]{\mathbf{#1}}$
Define $(x,y)$ as the old point and $(x^*,y^*)$ as the reflected point.
Intuitively, rather than a "formula", note that the line $y=2$ is horizontal. This means that the $x$ coordinate won't change. Also, the distance a point is below the line $y=2$ (I.e. $2-y$ where a negative below is taken to mean above) will be reflected to the same distance above the line. These can be written mathematically as
$$\begin{align}x^*&=x,\\y^*&=2+(2-y)=4-y.\end{align}$$
Edit
The matrix which reflects about the line $\vec{n}\cdot\vec{r}=0$, where $\vec{r}=[x,y]^T$, is $$R_\vec{n}=I-2\vec{n}\vec{n}^T.$$ This is able to represent a reflection about any line through the origin. In $2D$, with $\vec{n}=[n_1,n_2]^T$, this is
$$
R=\begin{bmatrix}1-2n_1^2&-2n_1n_2\\-2n_1n_2&1-2n_2^2\end{bmatrix}.
$$
Now, to perform a reflection about a line which passes through the point $\vec{p}$ rather than the origin, the point $\vec{p}$ is first translated to the origin, the standard reflection is performed, then the point is translated back. This is where the homogeneous coordinates comes into this problem. The matrix which translates $\vec{p}$ to the origin is $$T_p=\begin{bmatrix}I&-\vec{p}\\\vec{0}&1\end{bmatrix}.$$ In our $2D$ case, this is
$$T=\begin{bmatrix}1&0&-p_x\\0&1&-p_y\\0&0&1\end{bmatrix},$$
where $\vec{p}=[p_x,p_y]^T$. In homogeneous coordinates, the reflection can be written as
$$R_H=\begin{bmatrix}1-2n_1^2&-2n_1n_2&0\\-2n_1n_2&1-2n_2^2&0\\0&0&1\end{bmatrix}.$$ The matrix which performs the transformation is then
$$M=T^{-1}R_HT.$$
For your problem, $\vec{n}=[0,1]^T$, $\vec{p}=[0,2]^T$. The matrices can then be written as 
$$\begin{align}
R_H&=\begin{bmatrix}1&0&0\\0&-1&0\\0&0&1\end{bmatrix},\\
T&=\begin{bmatrix}1&0&0\\0&1&-2\\0&0&1\end{bmatrix},
\end{align}$$
from which we can calculate the transformation matrix
$$M=\begin{bmatrix}1&0&0\\0&-1&4\\0&0&1\end{bmatrix}$$
which reflects about the line $y=2$.
You would then have $S(\vec{p})=A\vec{p}+\vec{b}$, where $A=\begin{bmatrix}1&0\\0&-1\end{bmatrix}$ and $\vec{b}=\begin{bmatrix}0\\4\end{bmatrix}$.
