# How to find transformation matrix, specifically a rotation, between two given 3d vectors? [duplicate]

How to find transformation matrix, specifically a rotation, between two given 3d vectors?

I've found something about it but with quaternions. I don't know anything about quaternions. So it would be great to find solutions in terms of vectors.

I mean rotation matrix.

## marked as duplicate by Jonas Meyer, Ivo Terek, user147263, TooTone, hardmathAug 14 '14 at 23:37

• Do you mean to ask, given $\vec{a}, \vec{b} \in \mathbb{R}^3$, find $A$ s.t. $A \vec{a} = \vec{b}$? – gt6989b Oct 31 '12 at 16:09
• @gt6989b, yes i mean exactly this – Yola Apr 9 '13 at 9:42
• Question body should not be a continuation of the title; it should be readable on its own. Also, proper capitalization is not optional. – user147263 Aug 14 '14 at 22:59

I'm assuming you are asking that given $\vec{x} = (x_k)_{k=1}^3, \vec{y} = (y_k)_{k=1}^3 \in \mathbb{R}^3$, how do you find $A = (a_{i,j})_{i,j=1}^3 \in \mathbb{R}^{3 \times 3}$ so that $A \vec{x} = \vec{y}$.
In case $\{x_i\}_{i=1}^3$ are all non-zero, a simple diagonal matrix would do: define $a_{i,i} = y_i/x_i$ and let all off-diagonal elements be $0$.
If exactly one of the elements of $\vec{x}$ are zero, say $x_1 = 0$ then let $a_{1,1} = 0$ and $a_{1,2} = y_1/x_2$, leving the rest at 0.
If two of the elements of $\vec{x}$ are zero, say $x_1 = x_3 = 0$, define $a_{1,1} = a_{3,3} = 0$, $a_{1,2}$ as above, and $a_{3,2} = y_3/x_2$ to get what you need.
Finally, if $\vec{x} = \vec{0}$, it is not possible unless $\vec{y} = 0$ as well.