# vector projections using dot product

If there are 2 vectors A & B in 2D space and I want to project B onto A, My approach is to find the unit vector in the direction of A and multiply it with a scalar. Since the Dot product gives the amount of B in direction of A, the required scalar is given by the dot product between A & B.

Now, we have both direction and magnitude (scalar) for the projected vector.

But this is wrong compared to answers on the internet. I have to divide my result by the length of A again (i have done it once to find the unit vector in the direction of A). I do not understand why should I divide it again. Can someone please help me?

PS: Please don't use cosine to explain. I am trying to understand this as a topic of linear algebra which doesn't use trigonometric identities.

• You say the required scalar is given by "the dot product between $A$ and $B$." Where in this did you already divide by the length of $A$? Also: please show your exact work so we can see if something was done wrong.
– MPW
Commented Jan 30, 2023 at 18:58
• If you write $B=\lambda A+A_\perp$ with $\langle A,\,A_\perp\rangle=0$, you can show $\lambda=\frac{\langle A,\,B\rangle}{\Vert A\Vert^2}$. Is that ${}^2$ what you're asking about?
– J.G.
Commented Jan 30, 2023 at 21:54
• Yes, Can you please prove it? What is geometrical meaning of dividing the scalar quantity of dot product by the square of the length of the vector A? Commented Jan 31, 2023 at 0:24
• If $\langle \hat{A},B\rangle$ is the scalar projection, then $\langle\hat{A},B\rangle\hat{A}$ is the vector projection. Since there are two $\hat{A}$'s and $\hat{A}=A/\|A\|$, this is equivalent to $\langle A,B\rangle A/\|A\|^2$. Note the projection of $B$ onto $A$ only depends on $A$'s direction, not its magnitude. If you had two $A$'s in the numerator but only one $\|A\|$ in the denominator, the resulting quantity would scale with $A$'s magnitude, which we don't want. Commented Aug 28, 2023 at 16:06

We want the projection of $$B$$ along $$A$$ and along $$cA$$ (for any $$c \ne 0$$) to be equal. Since $$\langle{cA, B}\rangle = c \langle{A, B}\rangle$$, we have that $$\langle{cA, B}\rangle \cdot (cA) = c^2 \langle{A, B}\rangle\cdot A$$. This suggests that we should divide by something proportional to $$c^2$$. The correct quantity happens to be $$c^2||A||^2 = ||cA||^2 = \langle{cA, cA}\rangle$$, as can be verified by taking $$B = A$$, in which case we want the result to be $$A$$. In summary, the required projection is $$\frac{\langle{cA, B}\rangle}{\langle{cA, cA}\rangle} cA = \frac{\langle{A, B}\rangle}{\langle{A, A}\rangle} A.$$
Alternatively, following the suggestion by @J.B., if $$B = \lambda A + A^\perp$$ with $$\langle{A, A^\perp}\rangle = 0$$ then $$\langle{A, B}\rangle = \langle{A, \lambda A}\rangle + \langle{A, A^\perp\rangle} = \lambda \langle A, A\rangle$$ so $$\lambda = \frac{\langle{A, B}\rangle}{\langle{A, A}\rangle}$$.