How to rotate an object in-place along an arbitrary axis in three dimenstions

263 Views Asked by At

Consider the following cube floating in 3D space. How do I rotate it in-place along the axis specified by the vector $\vec{V}$?

enter image description here

I know how to rotate a point about an arbitrary axis, but it doesn't seem to be working for me.

I'm currently working on a computer application where the user would be able to rotate an object using the mouse and I want the object to spin in the direction the mouse is moving (i.e. imagine making a ball spin with your hand). So the arbitrary axes on which the cube will rotate will be both the up vector and right vector of the camera looking at the object.

1

There are 1 best solutions below

1
On

The image of a point $P$ in $3D$ after rotating it by an angle $\theta$ about an axis that has a unit direction vector $a$ and passing through a point $b$ is the point $Q$ given by

$ Q = b + R (P - b) $

where $R$ is the rotation matrix that depends only on the vector $a$ and the angle $\theta$, and is given by the famous Rodrigues' Rotation Matrix formula

$ R = {a a}^T + (I - {a a}^T) \cos(\theta) + S_a \sin(\theta) $

Here the skew-symmetric matrix $S_a$ is given by

$S_a = \begin{bmatrix} 0 && - a_z && a_y \\ a_z && 0 && -a_x \\ -a_y && a_x && 0 \end{bmatrix} $

Now given the $8$ vertices of the cube, you can apply the above formula, to generate their images resulting from rotation, and then you would have your new rotated cube by connecting the $8$ image vertices.