3D Vector Rotations – Understanding Rotations in 3D Space

3dlinear algebrarotationsvector-spaces

Assuming there are two vectors $P(x_p,y_p,z_p)$ and $Q(x_q,y_q,z_q)$ originating from the origin. Now, if I rotate vector $P$ to another position in space and obtain the coordinates $P'(x_p',y_p',z_p')$, how can I use the same rotation rule to obtain the coordinates of the rotated vector $Q'$? Can anyone provide me with some assistance?

for example, $P=(4,0,0)$, when we rotate $P$, assume we get $P′=(2,2,2\sqrt{2})$
, so if $Q=(1,2,3)$
, what $Q'$ is ?

Best Answer

Assuming $P$ is not parallel to $P'$, the unit-length axis of rotation is $k=\frac{P\times P'}{\lvert P\times P' \rvert}$, where $\times$ denotes the vector cross product. To find the angle of rotation, use dot product property $P \cdot P'=\lvert P\rvert\lvert P'\rvert \cos(\theta) $ to find the angle $\theta=\arccos\left(\frac{P\cdot P'}{\lvert P \rvert \lvert P' \rvert}\right)$ between $P$ and $P'$.

According to the "Matrix Notation" section of this Wikipedia article, the corresponding rotation matrix $R(k,\theta)$ is given by expression $I+\sin(\theta)[ k]_{\times}+(1-\cos(\theta))[k]_{\times}^2$, where $I$ is the identity matrix and the notation $[\cdot]_{\times}$ is explained here. This expression for $R$ is the referred to as the "matrix form of Rodrigues' rotation formula."

In other words, $Q'=R(k,\theta)Q$.

For speed, however, a computer implementation of this sort of axis-angle rotation should use quaternions instead of rotation matrices.

Edit: As noted by @peterwhy in the comments below, the above answer assumes that $P$ is not parallel to $P'$ and that we are looking for the unique axis of rotation $k$ and angle $\theta\in(0,\pi)$ such that the space curve $R(k,t)P$ from $P$ to $P'$ is a subset of the plane $\text{span}(P,P')$, where $t\in[0,\theta]$.

If we remove the 'space curve' requirement, we can uniquely determine a rotation axis $k$ and angle $\theta\in(0,\pi)$ given two pairs of vectors $P_1, P_1'$ and $P_2, P_2'$ such that $P_1,P_1'$ are not parallel and $P_2,P_2'$ are not parallel and $P_2$ and $P_2'$ do not have mirror symmetry over the plane bisecting $P_1$ and $P_1'$, i.e., $P_2'\neq 2 \frac{X\cdot P_2}{X\cdot X}X -P_2$, where $X=P_2-\left(P_2\cdot \frac{P_1'-P_1}{|P_1'-P_1|}\right)\frac{P_1'-P_1}{|P_1'-P_1|}$, the projection of $P_2$ onto the plane bisecting $P_1$ and $P_1'$.

Now, for convenience, let $k_0=\frac{(P_1'-P_1)\times(P_2'-P_2)}{|(P_1'-P_1)\times(P_2'-P_2)|}$. Assuming that $P_1,P_1'$ are not parallel and $P_2,P_2'$ are not parallel, if any non-undefined entry in element-wise division $\frac{k_0}{(P_1-(P_1\cdot k_0)k_0)\times(P_1'-(P_1'\cdot k_0)k_0)}$ is positive, $k=k_0$. Otherwise, $k=-k_0$. The corresponding angle $\theta$ is given by $\theta=\arccos\left(\frac{(P_1-(P_1\cdot k)k)\cdot(P_1'-(P_1'\cdot k)k)}{|(P_1-(P_1\cdot k)k)||(P_1'-(P_1'\cdot k)k)|}\right)$. If $\arccos\left(\frac{(P_1-(P_1\cdot k)k)\cdot(P_1'-(P_1'\cdot k)k)}{|(P_1-(P_1\cdot k)k)||(P_1'-(P_1'\cdot k)k)|}\right)\neq\arccos\left(\frac{(P_2-(P_2\cdot k)k)\cdot(P_2'-(P_2'\cdot k)k)}{|(P_2-(P_2\cdot k)k)||(P_2'-(P_2'\cdot k)k)|}\right)$, however, there is no axis or angle sending $P_1$ to $P_1'$ and $P_2$ to $P_2'$.

Note that there is likely a faster way than the one shown here to compute $k$ and $\theta$ under these new assumptions.

Edit 2: If instead given that $P_1=P_1'$ and $P_2$ is not parallel to $P_2'$, the method above the first edit section can be used on $P_1,P_1'$ to obtain $k$ and $\theta$. If $k$ is not parallel to $P_2\times P_2'$, however, there is no axis or angle sending $P_1$ to $P_1'$ and $P_2$ to $P_2'$.

If instead $P_1=P_1'$ and $P_2=-P_2'$, $k=\frac{P_1}{|P_1|}$ and $\theta=\pi$.

If instead $P_1=-P_1'$ and $P_2=-P_2'$, $\theta=\pi$ and $k=\frac{P_1\times P_2}{|P_1\times P_2|} $.

Finally, if instead $P_1$ is not parallel to $P_1'$ and $P_2=-P_2'$, $\theta = \pi$ and $k=\frac{P_2\times(P_1'-P_1)}{|P_2\times(P_1'-P_1)|}$.

I can go into more detail regarding the derivation and intuition behind the statements in "Edit" and "Edit 2" at @ZHIHA's request.