# Reflecting a vector over another line

So I'm really stuck with this math problem lately. I have a ray that is set along another line and gets reflected. What i am trying to do is to simply get reflected line's equation ($y = mx + c$). However, i think i should be using vectors. The problem is, even tho generally I understand them, I just can't get over how to use them in this case. I'm a senior so i haven't touched this topic yet and I need a little bit of help for my programming project.

I have two line equations and a point that the actual ray hits. I found this formula $r=d−2(d \cdot n)n$ where $r$ is the reflected line's vector, $n$ is the normal of a mirror, $d$ is the incident ray. How do i actually use these equations as vectors?!

an example is shown here

-Any help is reeaaally appreciated. Thaaanks!:))

• Your pink line has vector form $r=(x,y)=(x, \frac{2}{3}x+\frac{8}{3})=(0,\frac{8}{3})+x(1,\frac{2}{3})$ which has direction $(1,\frac{2}{3})$. A normal vector to the pink line is then $n = (-\frac{2}{3},1)$ - check this is perpendicular to the direction of the pink line. Find the direction of the red line and hence the direction of the yellow one.
– Paul
Apr 17, 2017 at 22:53

Start by rearranging the equation of the mirror line into $\frac23x-y=-\frac83$. The normal form of the equation of a line is $\mathbf n\cdot\mathbf x=\text{const}$, where $\mathbf n$ is some vector normal (perpendicular) to the line. Comparing this to the mirror line equation, I see that a normal to it is $\left(\frac23,-1\right)$. Since any normal will do, I’ll multiply this by $-3$ so that I don’t have to fiddle with as many fractions and so that the normal is on the same side of the line as the incident ray: $\mathbf n=(-2,3)$.

The incoming vector is $(1,m_{\text{in}})=(1,-1/3)$, which I’ll also multiply by $3$ to make the arithmetic simpler. Your reflection formula wants the normal to be a unit vector, but that can be dealt with by dividing by the length of $\mathbf n$ twice, once for each appearance in the formula. This is somewhat nicer for calculation anyway, since $\|\mathbf n\|^2=\mathbf n\cdot\mathbf n$ so that there’s no need to compute square roots. So, for the reflected ray, we have $$\mathbf r=\mathbf d-2{\mathbf d\cdot\mathbf n\over\mathbf n\cdot\mathbf n}\mathbf n = (3,-1)-2{(3,-1)\cdot(2,-3)\over(2,-3)\cdot(2,-3)}(-2,3)=\left(\frac3{13},\frac{41}{13}\right).$$ Divide the $y$-coordinate by the $x$-coordinate to find the corresponding outgoing slope, which is $41/3$. You know that the ray hits the mirror at $(5,6)$, so the equation of the reflected line is $(y-6)={41\over3}(x-5)$, or $$y={41\over3}x-{187\over3}.$$

You can also work entirely with normal vectors because the normal of the reflected line is the same as the reflection of the incoming line’s normal. The incoming normal can be read from the equation: $(-1/3,-1)$, or $(1,3)$ to simplify the arithmetic. The reflection formula produces $\left(\frac{41}{13},-\frac3{13}\right)$, which you can verify is perpendicular to the vector $\mathbf r$ computed previously. The equation of the outgoing line is then $41x-3y=\dots$ (I’ve multiplied the entire equation by $13$ to eliminate the fractions.) Referring to the general normal equation at the top of this answer, it says that the dot product of $\mathbf n$ with every point on the line is constant, so we can find this constant by taking the dot product with any known point—$(5,6)$ in this case. This gives $41x-3y=187$, which should be looking a bit familiar. Rearranging this equation to isolate $y$ produces the same one as computed previously.

• Thaanks for helping me out! Apr 19, 2017 at 8:27

Here is another option. There is a formula for the angle between two lines, given their slopes. \begin{alignat*}{1} \tan\Delta\theta & =\frac{k_{1}-k_{2}}{1+k_{1}k_{2}}. \end{alignat*} So $k_{1}=-\frac{1}{3}$ (red), $k_{2}=-\frac{3}{2}$ (green), $k_{3}=??$ (yellow), and then solve the equation for $k_{3}$: \begin{alignat*}{1} \frac{k_{1}-k_{2}}{1+k_{1}k_{2}} & =\frac{k_{2}-k_{3}}{1+k_{2}k_{3}}. \end{alignat*}

It is clear that your problem will be the same if you shift point $A$ at the origin, with lines

• line $y=(-1/3)x$ whose directing vector is $\binom{-3}{1}$

• and line of reflection $y=(2/3)x$ with directing vector $d=\binom{3}{2}$, that we will need normalized $n=\binom{3a}{2a}$ where $a=\tfrac{1}{\sqrt{13}}$.

Your formula, connects the incident vector $d$ and the reflected vector $r$

$$\tag{1}r=d−2(d \cdot n)n$$

If we apply (1) with the expressions of $d$ and $n$ given above, we get:

$$r=\binom{3/13}{41/13}$$

which is the directing vector of line $y=mx$, meaning that $m=41/3$.

The value of $c$ is obtained by expressing that $y=mx+c$ contains point $A(5,6)$ which means that $6=\tfrac{41}{3}5+c$, thus $c=-187/3.$

The equation of the line $y=mx+c$ is thus $y=\tfrac{41x-187}{3}$

• Thank you all for all these explanations! Apr 18, 2017 at 21:21