0

in doing Project Euler problem #144, I needed to be able to reflect a point across a line without any kind of trig. So I looked up how to do it and the only bit of information came from Wikipedia.

http://en.m.wikipedia.org/wiki/Reflection_(mathematics)#Reflection_across_a_line_in_the_plane

i know the syntax of the operation and how to do it, and it solved the problem successfully however it's kind of annoying that I'm unable to find a proof or explanation of this anywhere. So does anyone have any idea why this works? Any explanation or proof would be greatly appreciated.

2 Answers2

2

Let $v'$ be the reflection of vector $v$ through the blue line in the figure below:

enter image description here

Drawing a line through the tips of the two vectors, we form two mirror-image right triangles. The triangle with $v$ as hypotenuse shows $v$ as the sum of two vectors,

$$v = v_{\parallel} + v_{\perp} $$

where $v_{\parallel}$ is a component parallel to the line and $v_{\perp}$ is a component perpendicular to the line. The vector $v_{\parallel}$ is also called the projection of $v$ onto the line.

The other triangle (with $v'$ as hypotenuse) illustrates the vector difference

$$v' = v_{\parallel} - v_{\perp}\; . $$

If we add $v$ and its reflection, we get

$$v + v' = (v_{\parallel} + v_{\perp}) + (v_{\parallel} - v_{\perp}) = 2 v_{\parallel} $$

and therefore

$$ v' = 2 v_{\parallel} - v \;. $$

The rest of the details of the formula are simply a way to compute $v_{\parallel}$:

$$ v_{\parallel} = \frac{v\cdot p}{||p||^2} \, p = \frac{v\cdot p}{p\cdot p} \, p $$

where $p$ is any non-zero vector parallel to the line (the same as $l$ in your formula, but I find the symbol $l$ a little too easy to confuse with other symbols). There are many places to see this formula for the projection of a vector derived, including the answers to this question.


Note that we can also take

$$v - v' = (v_{\parallel} + v_{\perp}) - (v_{\parallel} - v_{\perp}) = 2 v_{\perp} $$

from which we can derive the formula

$$v' = v - 2 v_{\perp} = v - 2 (v \cdot \hat n)\, \hat n $$

where $\hat n$ is a normal vector of the line, that is, a unit vector perpendicular to the line, so that $v_{\perp} = (v \cdot \hat n)\, \hat n$. This is a more general formula that works for planes and hyperplanes (where the "direction" of the reflecting surface is not given by a single vector parallel to the surface) as well as for lines. For example, see this question.

David K
  • 108,155
1

In Euclidean geometry, $a\cdot b=|a||b|\cos\theta$ where $\theta$ is the angle between $a$ and $b$. So first note that if $v$ is on your line then

$2\frac{v\cdot l}{l\cdot l}l-v=2\frac{|v|\cos\theta}{|l|}l-v$ and here $\theta=0$ and so we get $2|v|/|l| l -v$. But since $l$ is a scalar multiple of $v$ we have $\frac{|v|}{|l|}l=v$ so the reflection of $v$ is just $v$, which is what we expect!

(Since the line goes through zero, this is equivalent to saying that the point $v$ is parallel to the line, since we can think of the point $v$ as defining the line $OV$.)

Now, lets do it for something perpendicular to the line. In this case $\theta=90$ degrees and so $\cos\theta=0$. This means that the fractional part will be $0$ and so the refelection of $v$ is just $-v$, again as we expect.

I won't prove the rest for you, but this is enough, since any other point can be written as a sum of a "parallel" and "perpendicular" point, and we have shown that the formula works for them, hence it works for any point.