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:
- Store angles from each plane in 6-sized array. $(XY : 30, XZ : 50 , XW : 20…)$
- Build a traditional plane-rotation $4\times4$ matrix for each of the plane.
- Multiply these 6 matrices.
But multiplying 6 $4\times4$ matrix every time would be pretty performance-consuming, so what I want to do is:
- Set the base vector to $V (1, 0, 0, 0)$.
- Store the rotation destination vector, like $W (0, 0, 1, 0)$
- 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.)