0
$\begingroup$

Introduction

I'm trying to understand rotation around an arbitrary axis in 3D. Have plumbed the depths of StackExchange and read up my best on the various methods around, but am pretty confused in general. I however do have a method which seems like it works, but would love confirmation / rejection of it; even better would be help connecting the method here to the standard methods.

Assumptions

Let's assume:

  1. We already have matrices for rotation about the $x$, $y$, and $z$ axes.
  2. The given vector to rotate around, $\vec{v}$, is normalized
  3. The point we're rotating is already at the origin.
  4. We'd like to rotate around $\vec{v}$ by some angle $\lambda$.
  5. The coordinate system has $x$ as left-right, $z$ as forward-back, and $y$ as up-down.

Understanding of the solution

My understanding is that we'd like to first rotate around the $y$ axis by the angle between $\vec{v}$ and the $xy$ plane. This produces a new vector $\vec{v'}$, which we'd like to rotate around the $z$ axis by the (negative of the) angle $\phi$ between the $\vec{v'}$ and the $xz$ plane; then, we have effectively rotated the original vector to be coincident with the $x$ axis, so we rotate around the $x$ axis by $\lambda$, and then invert the second rotation, then invert the first rotation.

Solution

Step 1

projection to xz

Determine the angle $\theta$ between $\vec{v}$ and the $xy$ plane. We can do this by observing the projection of $\vec{v}$ on the $xz$ plane. Here we have a triangle formed with $v_x$, $v_z$, and $\sqrt{{v_x}^2 + {v_z}^2}$. The angle we're looking for, $\theta$ can be found by $\arctan{\frac{v_x}{v_z}}$. Our first job is therefore to rotate around the $y$ axis by this $\theta$. This brings our original vector to the $xy$ plane. We will call this $\vec{v'}$.

Key observations after Step 1

  1. $||\vec{v'}|| == ||\vec{v}|| == \sqrt{v_x^2 + {v_y}^2 + {v_z}^2}$
  2. Because we rotated around the $y$ axis, $v_y' == v_y$.
  3. Similarly, $||v_{xz}'|| == ||v_{xz}||$. BUT, since we have rotated over to the $xy$ plane, now $v_x' == ||v_{xz}||$ and $v_z' == 0$.

Step 2

vprime_phi

Now we'd like to find the angle $\phi$ between $\vec{v'}$ and the $xz$ plane. To do this, we can use the above observations, and infer that $\phi$ can be found via $-1 * \arctan{\frac{v_y}{\sqrt{{v_x}^2 + {v_z}^2}}}$. So we rotate around the z axis by this $\phi$, leaving us with a vector $\vec{v''}$ which is coincident with the $x$ axis.

Step 3

Finally, we rotate around $x$ by $\lambda$, and then multiply by the inversions of the matrices used in step 2 and step 1, in that order.

Conclusion

It's my understanding that this method can be done the same way if we rotate to the $xz$ plane first, then over to the $xy$ plane; likewise, we could rotate to the $yz$ plane first, etc. We could also use methods to determine the angles - for instance, $\phi$ could be found via $\arccos(\frac{v_y}{\sqrt{{v_x}^2 + {v_y}^2 + {v_z}^2}})$. Am sorry if anything is unclear above, please ask for more info if required. Thanks in advance for your help!

$\endgroup$
2
  • $\begingroup$ Instead of all this, you can just use the Rodrigues Rotation matrix formula. Look it up. $\endgroup$
    – of course
    Oct 11, 2022 at 21:59
  • 1
    $\begingroup$ If you have a unit vector axis $a$ and angle $\theta$, then quaternions make this very simple. Interpret $a$ as an imaginary quaternion $a = a_xi + a_yj + a_zk$. Then form the quaternion $q = \cos\theta/2 + a\sin\theta/2$. The rotation of a vector $v$ (interpreted as an imaginary quaternion) by $\theta$ around the axis $a$ is then $qv\bar q$ where $\bar q$ is the conjugate. You can get the rotation matrix by choosing $v$ to be each basis vector, i.e. $$ qi\bar q,\quad qj\bar q,\quad qk\bar q $$ are the columns of the rotation matrix. $\endgroup$ Oct 14, 2022 at 16:13

1 Answer 1

1
$\begingroup$

As an alternative to your method, which works, you can use spherical coordinates to express the axis of rotation $\mathbf{v}$ as follows

$ \mathbf{v} = [ \sin \theta \cos \phi, \sin \theta \sin \phi, \cos \theta ]^T $

Then construct the following two unit vectors that are orthogonal to $\mathbf{v}$ and also to each other,

$ \mathbf{u_1} = [ \cos \theta \cos \phi, \cos \theta \sin \phi, -\sin \theta ]^T$

$ \mathbf{u_2} = [-\sin \phi, \cos \phi, 0 ]^T $

Now assemble the three vectors together into one matrix $R$ as follows

$ R = [ \mathbf{v} , \mathbf{u_1}, \mathbf{u_2} ] $

The columns of matrix $R$ represent a basis for $\mathbb{R}^3$. In this basis, the coordinate of a given point $P = (x, y, z)$ is

$Q =(x',y',z') = R^T \ P $

Now we want to rotate $P$ about $\mathbf{v}$ by an angle $\lambda$. This means that we're rotating $Q$ about the the $x'$ axis (the first column of $R$). The rotated point will have its coordinates (in the basis $R$) as

$ Q' = R_{x'} \ Q = \begin{bmatrix} 1 && 0 && 0 \\ 0 && \cos \lambda && - \sin \lambda \\ 0 && \sin \lambda && \cos \lambda \end{bmatrix} \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} $

Finally express the rotated point in the standard basis, as follows

$ P' = R \ Q' = R \ R_{x'} \ Q = R \ R_{x'} \ R^T \ P $

So that the overall rotation matrix in the standard basis is given by

$ R_{v} = R \ R_{x'} \ R^T $

This expression requires the evaluation of the matrix $R$ with $\mathbf{v}, \mathbf{u_1} , \mathbf{u_2} $ as its columns. In what follows, I'll eliminate the requirement to calculate $\mathbf{u_1}$ and $\mathbf{u_2}$, and I will produce an expression that depends only on $\mathbf{v}$ and the angle $\lambda$.

Recall that $R = [ {\mathbf{v} , \mathbf{u_1}, \mathbf{u_2}} ] $, so the above expression for the overall rotation matrix becomes,

$R_{v} = {\mathbf{v} \mathbf{v}}^T + \cos(\lambda) \bigg( {\mathbf{u_1} \mathbf{u_1}}^T + {\mathbf{u_2} \mathbf{u_2}}^T \bigg) + \sin(\lambda) \bigg( - {\mathbf{u_1} \mathbf{u_2}}^T + {\mathbf{u_2} \mathbf{u_1}}^T \bigg) $

Since ${R R}^T = I$, then ${\mathbf{u_1} \mathbf{u_1}}^T + {\mathbf{u_2} \mathbf{u_2}}^T = I - {\mathbf{v} \mathbf{v}}^T $

The sine term needs some careful consideration. If $P$ is any point in $\mathbb{R}^3 $, then its coordinates in the basis defined by the columns of $R$ is

$ Q = (x',y', z') = R^T P $

i.e. $ P = x' \mathbf{v} + y' \mathbf{u_1} + z' \mathbf{u_2} $

where

$ x' = \mathbf{v}^T P $

$ y' = \mathbf{u_1}^T P $

$ z' = \mathbf{u_2}^T P $

The vector $W = \bigg( - {\mathbf{u_1} \mathbf{u_2}}^T + {\mathbf{u_2} \mathbf{u_1}}^T \bigg) P = y' \mathbf{u_2} - z' \mathbf{u_1} $

Now consider the cross product:

$\mathbf{v} \times P = \mathbf{v} \times (x' \mathbf{v} + y' \mathbf{u_1} + \mathbf{u_2} ) = 0 + y' \mathbf{u_2} - z' \mathbf{u_1} $

Comparing the two expressions above, we deduce that

$\bigg( - {\mathbf{u_1} \mathbf{u_2}}^T + {\mathbf{u_2} \mathbf{u_1}}^T \bigg) P = \mathbf{v} \times P $

This cross product between $\mathbf{v}$ and $P$ can be expressed as a matrix multiplication as follows

$ \mathbf{v} \times P = S_v P = \begin{bmatrix} 0 && - v_z && v_y \\ v_z && 0 && - v_x \\ - v_y && v_x && 0 \end{bmatrix} P $

In summary, the rotation matrix is given by

$ R_v(\lambda) = \mathbf{v} \mathbf{v}^T + \cos(\lambda) (I - \mathbf{v} \mathbf{v}^T)+ \sin(\lambda) S_v $

And this is the well-known formula for the rotation matrix known as Rodrigues' Rotation Matrix Formula.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .