Extending a vector so its projection match another vector's length, there's a name for that?

122 Views Asked by At

My Problem

I'm a game developer, and I had a problem yesterday in which I needed to extend a vector $\vec{v}$ so its projection into $\vec{w}$ was equal to $||\vec{w}||$.

(Illustrating the Problem)

How I solved the problem

By using the projection of $\vec{w}$ into $\vec{v}$, its perpendicular distance, and a bit of trigonometry, I was able to get to this formula: $$vNewLength=\frac{||\vec{w}||^2}{projection}$$

Illustrating how I solved the problem (Illustrating how I solved the problem)

PS.: The final formula is slightly wrong on the picture, sorry, it should be $||\vec{w}||^2$ instead of $\vec{v}$

There's a name for that?

I would like to know if this is a known operation between vectors, and what's the name so I can look it up to expand my knowledge on the topic.

Edit (29/May/2023).: For future reference, I discovered that another way of approaching this problem is to use secant: $$x=hypotenuse*\sec(\alpha)=||\vec{w}||*\frac{||\vec{w}||}{projection}=\frac{||\vec{w}||^2}{projection}$$

1

There are 1 best solutions below

1
On

I don't know that there's a name for this operation, but the math can be simplified using the dot product/inner product. In a 2D cartesian coordinate system, the dot product can be calculated by $\vec{v}\cdot\vec{w} = v_x w_x + v_y w_y.$

The dot product $\vec{v}\cdot\vec{w}$ is equal to the length of the projection of $\vec{v}$ onto $\vec{w}$ multiplied by the length of $\vec{w}$. So, the length of the projection of $\vec{v}$ onto $\vec{w}$ is equal to $\vec{v}\cdot\vec{w}/||\vec{w}||.$ We want a scalar $k$ to scale $\vec{v}$ so that $$k\vec{v}\cdot\left(\frac{\vec{w}}{||\vec{w}||}\right) = ||\vec{w}||.$$ This results in $$k = \frac{||\vec{w}||^2}{\vec{v}\cdot\vec{w}}.$$ Finally, the new length of $\vec{v}$ is $k||\vec{v}||.$