Get a rotation matrix which rotates $ 4D $ vector to another $4D$ vector

geometrylinear algebra

I'm trying to figure out how to rotate a 4d vector to another 4d vector, for example, $(0.5, 0.5, 0.5, 0.5)$ to $(0, 0, 0, 1)$. I first thought just like $3d$ space, using a dot product to find the angle and cross product to find the axis would do, but there was no cross product in $4d$, so I've got confused. I tried searching but all I figured out was my lack of knowledge and understanding about linear algebra.

I first tried to do like this:

  1. Store angles from each plane in 6-sized array. $(XY : 30, XZ : 50 , XW : 20…)$
  2. Build a traditional plane-rotation $4\times4$ matrix for each of the plane.
  3. Multiply these 6 matrices.

But multiplying 6 $4\times4$ matrix every time would be pretty performance-consuming, so what I want to do is:

  1. Set the base vector to $V (1, 0, 0, 0)$.
  2. Store the rotation destination vector, like $W (0, 0, 1, 0)$
  3. Build a matrix (or formula, anything) to rotate from $V$ to $W$, and apply this to it's children.

What would be the efficient method?

I wanted to utilize something like this answer, but it was beyond my understanding 🙁

Best Answer

There are infinitely many rotation matrices that send a unit vector $u$ to another unit vector $v$, even in 3D that's true. But there is a unique rotation which restricts to a rotation in $\mathrm{span}\{u,v\}$ by angle $\angle uv$ (so it rotates $u$ to $v$) and fixes the orthogonal complement of $\mathrm{span}\{u,v\}$. Its formula is

$$ R = I -\frac{(u+v)}{1+\langle u,v\rangle}(u+v)^T+2vu^T $$

assuming $u,v$ are unit column vectors with $u+v\ne0$. This is true in any dimension. See here.

(I assume you don't want to learn about quaternions.)

Related Question