reflect a 2D vector over another vector without using normal, why this gives the wrong result?

3k Views Asked by At

I'd like to reflect vector $\mathbf{v_1}$ relative to the line through the origin defined by $\mathbf{v_2}$ without calculating the normal to $\mathbf{v_2}$ first.

For example if my mirror is along the x axis so that $v_2$ is $(2, 0)$, and the original vector $\mathbf{v_1}$ is $(1, -1)$, I expect the reflected vector to be $(1, +1)$

The equation given in Wikiepdia's Reflection (mathematics); Reflection across a line in the plane is

$$\mathbf{v_{refl}} = \mathbf{v_1} - 2 \frac{\mathbf{v_1} \cdot \mathbf{v_2}}{\mathbf{v_2} \cdot \mathbf{v_2}}\mathbf{v_2}$$

However I get $(-1, -1)$ as if it were reflected by the y axis; the normal to my plane.

Am I misunderstanding how this equation should be used? Is there a different expression that gives me the reflection without calculating the normal first explicitly?

enter image description here

2

There are 2 best solutions below

3
On BEST ANSWER

Here is the general situation: General Situation

It all boils down to vector addition, scalar multiplication and vector projection.

We're given $\vec{v_1}=\begin{bmatrix}1\\-1 \end{bmatrix}$ and $\vec{v_2}=\begin{bmatrix} 1\\0\end{bmatrix}$. We're asked to calculate $v_{\text{refl}}$.

$\large{k = \frac{\vec{v_1}\cdot\vec{v_2}}{\vec{v_2}\cdot\vec{v_2}} = \frac{\begin{bmatrix}1\\-1 \end{bmatrix}\cdot\begin{bmatrix} 1\\0\end{bmatrix}}{\begin{bmatrix}1\\0 \end{bmatrix}\cdot\begin{bmatrix} 1\\0\end{bmatrix}}} =1$

and

$\begin{align*}\color{green}{v_{\text{refl}}} &= \color{red}{- v_1}+\color{orange}{2kv_2} \\&= -v_1+2v_2 &&, k=1 \\&= -\begin{bmatrix} 1\\-1\end{bmatrix}+2\begin{bmatrix} 1\\0\end{bmatrix} \\&= \begin{bmatrix} 1\\1\end{bmatrix} \end{align*} $

So, yes, the formula from wikipedia $v_{\text{refl}}=v_1 - 2kv_2$ is not $100\%$ correct. To get the right result, multiply the result $\begin{bmatrix}-1\\-1\end{bmatrix}$, that you've got using the formula from wikipedia, by $-1$, because the right formula is $v_{\text{refl}}=-v_1 + 2kv_2$.

3
On

Instead of relying on found or memorized formulas, try to work this out for yourself from the fundamentals. The basic idea is that the vector $\mathbf v$ to be reflected is decomposed as $\mathbf v_\parallel+\mathbf v_\perp$, its respective components parallel to and perpendicular to the reflector. The reflection is then accomplished by reversing the perpendicular component, i.e., it is $\mathbf v_\parallel-\mathbf v_\perp$. Either of these components can be found via orthogonal projection; the other is then simply the difference between it and the original vector. Thus, the reflection of $\mathbf v$ can be expressed as either $$\mathbf v_\parallel - (\mathbf v - \mathbf v_\parallel) = 2\mathbf v_\parallel-\mathbf v$$ or $$(\mathbf v-\mathbf v_\perp)-\mathbf v_\perp = \mathbf v-2\mathbf v_\perp.$$ In your question, the reflector is spanned by $\mathbf v_2$, so you can compute $\mathbf v_\parallel$ directly via orthogonal projection onto $\mathbf v_2$ and then use the first form. When the reflector is a hyperplane for which you know the normal, then the second form is more convenient since you only have to project onto that normal to find $\mathbf v_\perp$.