# How to find the rotation matrix that will align an arbitrary vector to an axis

If I have a vector that starts at the origin, how can I find the transformation matrix that will align it with the positive y-axis. So it basically turns into a positive-y axis?

EDIT: I also forgot to mention this is in a 3d space

Use the Euler-Rodrigues formula to find the rotation matrix $\mathbf{R}$: $$\mathbf{R} = \cos\theta (\mathbf{I} - \mathbf{a}^T \mathbf{a})+ \mathbf{a}^T \mathbf{a} + \sin\theta\,\mathbf{A}$$ where $\mathbf{a}$ is the axis of rotation and $\theta$ is the angle of rotation. $\mathbf{I}$ is the identity matrix. The matrix $\mathbf{A}$ is skew-symmetric and is related to $\mathbf{a}$ by its action of a vector $\mathbf{v}$ as $$\mathbf{A}\cdot\mathbf{v} = \mathbf{a}\times\mathbf{v} \,.$$ To find the axis of rotation you will have to compute $\mathbf{a} = \mathbf{e}_y\times\mathbf{w}$ where $\mathbf{e}_y$ is the $y$-axis vector and $\mathbf{w}$ is your starting vector. The angle $\theta$ can be found from $\mathbf{e}_y\cdot\mathbf{w}$.