Point reflection across a line

It is useful to think about this by using vectors. Suppose that your points are $p,q,a \in \mathbb{R^2}$.

Then $x = p + (q-p)t$ is a point on the line $pq$. We wish to find the projection of $a$ on the line. To do this we require $\|x - a\|^2 = \|x\|^2 + \|a\|^2 - 2 (x \cdot a)$ to be minimal. That is we have to minimize $$\|p + (q-p)t\|^2 + \|a\|^2 - 2 (p + (q-p) t) \cdot a)$$ w.r.t $t$. To do this we write this as $$\|p\|^2 + \|q-p\|^2 t^2 + 2 t p \cdot (q-p) + \|a\|^2 - 2(p \cdot a) - 2 t (q-p) \cdot a.$$ This is a quadratic in $t$ with minimum at the tip of the parabola: $$t = \frac{-2 p \cdot (q-p) + 2 (q-p) \cdot a}{2\|q-p\|^2} = \frac{(q-p) \cdot (a-p)}{\|q-p\|^2}.$$

Thus the projection is given by $$x = p + (q-p) \frac{(q-p) \cdot (a-p)}{\|q-p\|^2}$$ and the reflection is then just $x + (x-a) = 2x-a$.

This method doesn't have problems with infinite slopes.


You find the equation of the line through p and q, one version of which is $$\frac{y-y_p}{x-x_p}=\frac{y_q-y_p}{x_q-x_p}$$ The slope is the RHS. So the slope of the line through a and perpendicular to the line through p and q is $$\frac{-(x_q-x_p)}{y_q-y_p}$$ and the line is $$y-y_a=\frac{-(x_q-x_p)}{y_q-y_p}(x-x_a)$$ Calculate the distance from a to the line through p and q and extend that far again. I think there is a formula for this, but don't know it, so I would have to solve the two equations for x and y to get the intersection. Note that there is a divide by zero concern.