Find projection of vector so that it shares the magnitude of another one

32 Views Asked by At

Given N-dimensional vectors $a$ and $b$, I want to compute a new vector $c$ that has the direction of $a$ and the magnitude of $b$.

In 2 dimensions, this is solvable with trig:

\begin{align} \rho &= ||y||_2 \\ \theta &= \tan^{-1}(\frac{a_y}{a_x}) \\ c_x &= \cos(\theta) * \rho \\ c_y &= \sin(\theta) * \rho \end{align}

How do I compose a general solution that works over any amount of spatial dimensions?

1

There are 1 best solutions below

0
On BEST ANSWER
  1. Compute the unit vector of $a$ by dividing it by its own magnitude. This projects it onto the surface of a hypersphere that has a radius of 1 unit and is centred on the origin.

$$ \upsilon = \frac{a}{||a||} $$

  1. Multiply the unit vector by the magnitude of $b$:

$$ c = ||b|| * \upsilon $$