[Math] Vector Reflection Matrix over line

linear algebramatricesreflectionvectors

I need to find a matrix that reflects vectors over any line y= mx + b. Furthermore, I need to be able to find the components of both of these vectors.

Thanks!

Best Answer

Here are two approaches to solving this:


Method 1: Find the equation of the line through a point $P$ that’s perpendicular to the given line, then find the distance from $P$ to the given line. $P$’s reflection will be twice that distance along the perpendicular.

The perpendicular line through the point $(x_0,y_0)$ is described by the parametric equations $$\begin{align}x&=x_0-mt \\ y&=y_0+t.\end{align}$$ Substitute into the equation of the given line and solve for $t$:$$ y_0 + t = m(x_0 - mt) + b \\ t = {mx_0-y_0+b \over m^2+1} $$ and then substitute $2t$ into the parametric equations: $$\begin{align} x' &= x_0+2m{mx_0-y_0+b \over m^2+1} = -{m^2-1 \over m^2+1} x_0 + {2m \over m^2+1} y_0 - {m \over m^2+1}2b\\ y' &= y_0+2{mx_0-y_0+b \over m^2+1} = {2m \over m^2+1} x_0+{m^2-1 \over m^2+1} y_0+{1 \over m^2+1}2b. \end{align}$$ The constant terms mean that this transformation can’t be represented by a $2\times2$ matrix, but if we use homogeneous coordinates, representing the point $(x,y)$ by the vector $\langle x, y, 1\rangle^T$, we can represent the transformation by the matrix $$ M = \pmatrix{-{m^2-1 \over m^2+1} & {2m \over m^2+1} & -{2mb \over m^2+1} \\ {2m \over m^2+1} & {m^2-1 \over m^2+1} & {2b \over m^2+1} \\ 0 & 0 & 1}. $$


Method 2: Solve a simple case and generalize it by applying suitable transformations.

Reflecting about the $x$-axis is easy—you just negate the $y$-coordinate. Call that transformation $M_x$. If we can find a rigid motion that takes the line $y=mx+b$ onto the $x$-axis, then we simply apply that, reflect, and then move the line back to where it belongs. Translating the line so that it passes through the origin is easy, too: just subtract $b$ from the $y$-coordinate. Call that transformation $T_{-b}$. To get the line to coincide with the $x$-axis, it now needs to be rotated. Using the usual convention for angles, this can be done by rotating clockwise through an angle of $\theta$, where $\tan\theta=m$, that is, rotating through an angle of $-\theta$. We’ll call that transformation $R_{-\theta}$. Putting it all together, we get $$ M = \left(R_{-\theta}T_{-b}\right)^{-1}M_x\left(R_{-\theta}T_{-b}\right) = T_bR_\theta M_xR_{-\theta}T_{-b}. $$ Again, because of those translations, this can’t be represented as a $2\times2$ matrix, so we’ll need to use homogeneous coordinates, in which a translation matrix is of the form $$\pmatrix{1&0&\Delta x\\0&1&\Delta y\\0&0&1}.$$ The matrix for $M_x$ is just the identity with a $-1$ in the second diagonal entry. The rotation matrices take a bit more work, since we don’t actually have the angle $\theta$, but we don’t need it. We need its sine and cosine, which we can get from the slope of the line: $$\begin{align} \sin\theta &= {\Delta y\over\sqrt{\Delta x^2+ \Delta y^2}}={m\Delta x\over\sqrt{\Delta x^2+m^2\Delta x^2}}={m\over\sqrt{1+m^2}}. \end{align}$$ A similar calculation produces $\cos\theta=1/\sqrt{1+m^2}$. This gives $$ R_\theta = \pmatrix{{1\over\sqrt{1+m^2}} & -{m\over\sqrt{1+m^2}} & 0 \\ {m\over\sqrt{1+m^2}} & {1\over\sqrt{1+m^2}} & 0 \\ 0 & 0 & 1}, $$ and $R_{-\theta}$ is this matrix with the signs of the off-diagonal elements flipped. Putting it all together, we have $$ \pmatrix{1&0&0\\0&1&b\\0&0&1} \pmatrix{{1\over\sqrt{1+m^2}} & -{m\over\sqrt{1+m^2}} & 0 \\ {m\over\sqrt{1+m^2}} & {1\over\sqrt{1+m^2}} & 0 \\ 0 & 0 & 1} \pmatrix{1&0&0\\0&-1&0\\0&0&1} \pmatrix{{1\over\sqrt{1+m^2}} & {m\over\sqrt{1+m^2}} & 0 \\ {-m\over\sqrt{1+m^2}} & {1\over\sqrt{1+m^2}} & 0 \\ 0 & 0 & 1} \pmatrix{1&0&0\\0&1&-b\\0&0&1}. $$ This isn’t as bad as it looks. All of those zeros and ones make the multiplications fairly simple. Once you multiply it all out, you get the same matrix as you did with method 1. It’s not too hard to check that the determinant of this matrix is $-1$, which is what we expect for a reflection.