How can I calculate a $4\times 4$ rotation matrix to match a 4d direction vector? I have two 4d vectors, and need to calculate a $4\times 4$ rotation matrix to point from one to the other.
edit - I'm getting an idea of how to do it conceptually: find the plane in which the vectors lie, calculate the angle between the vectors using the dot product, then construct the rotation matrix based on the two. The trouble is I don't know how to mechanically do the first or last of those three steps. I'm trying to program objects in 4space, so an ideal solution would be computationally efficient too, but that is secondary.

Let the two vectors be $u$ and $v$. Normalise them to unit vectors. Put the two column vectors together to form a $4\times 2$ matrix $A=(u,v)$. Perform an orthogonal diagonalisation $AA^T=QDQ^T$. Permute the diagonal entries of $D$ so that they are arranged in descending order. Permute the columns of $Q$ accordingly. Then $Q^T$ is a real orthogonal matrix that maps $u$ and $v$ to the $xy$-plane, so that $Q^TA$ is of the form $\pmatrix{x_1&x_2\\ y_1&y_2\\ 0&0\\ 0&0}$. Define two $2\times2$ rotation matrices $R_1=\pmatrix{x_1&-y_1\\ y_1&x_1}$ and $R_2=\pmatrix{x_2&-y_2\\ y_2&x_2}$. Then the desired rotation matrix can be taken as $R=Q\pmatrix{R_2R_1^T\\ &I_2}Q^T$ and we have $Ru=v$.
Remark. Instead of using orthogonal diagonalisation, you may also compute the $Q$ in the above by singular value decomposition: just compute the SVD $A=Q\Sigma P^T$ and take the $Q$.
