Analytic Geometry – Point Reflection Across a Line

analytic geometrylinear algebrareflection

Let's say that we have three points: $p = (x_p,y_p)$, $q = (x_q,y_q)$ and $a = (x_a,y_a)$. How can i find point $b$ which is reflection of $a$ across a line drawn through $p$ and $q$? I know it's simple to calculate, when we have $p$, $q$ etc. But I want to do this in my program, and I'm not sure, how to compute this.

OK, I've found solution by myself (but answers in this topic really helped me).

Suppose, that we have a line $Ax+By+C=0$, and $A^2+B^2 \not= 0$. $M (a,b)$ reflection across the line is point: $M' (\frac{aB^2-aA^2-2bAB-2AC}{A^2+B^2}, \frac{bA^2-bB^2-2aAB-2BC}{A^2+B^2})$

In my case, we don't have line, but only 2 points. How we can find $A,B,C$? It's simple:

Let's say, that $p=(p_x,p_y)$ and $q = (q_x,q_y)$. Line equation is: $(y-p_y)(q_x-p_x) – (q_y-p_y)(x-p_x) = 0$

After some calculations we have: $y(q_x-p_x) – x(q_y-p_y) – (p_y(q_x-p_x)+p_x(p_y-q_y)) = 0$

So:
$A = p_y-q_y$, $B = q_x-p_x$ and $C = -p_y(q_x-p_x)-p_x(p_y-q_y)$.

That's all.

Best Answer

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.

Related Question