2

I was wondering how it would be possible for me to rotate a cube diagonally 360 degrees.

I am able to rotate it over the x-axis, y-axis and z-axis with the following formulas :

**x-axis**

y = v.y*cos(degree) - v.z*sin(degree);
z = v.y*sin(degree) + v.z*cos(degree);

**y-axis**

x = v.z * sin(degree) + v.x * cos(degree);
z = v.z * cos(degree) - v.x * sin(degree);

**z-axis**

x = v.x * cos(degree) - v.y * sin(degree);
y = v.x * sin(degree) + v.y * cos(degree);

Thanks in advance!

Unknown
  • 23

2 Answers2

2

Wikipedia will tell you everything: http://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle

2

Given two vectors, $u$ and $v$, the cross-product with $u$ can be written in matrix form: $$ \begin{align} u\times v &=\begin{bmatrix}0&-u_3&u_2\\u_3&0&-u_1\\-u_2&u_1&0\end{bmatrix} \begin{bmatrix}v_1\\v_2\\v_3\end{bmatrix}\\[6pt] &=Y_uv\tag{1} \end{align} $$ Suppose $u$ is a unit vector. Then $u\times v$ is the orthogonal projection of $v$ onto the plane perpendicular to $u$ rotated $\pi/2$ (it is perpendicular to both $u$ and $v$).

The orthogonal projection of $v$ onto $u$ is given by $$ \begin{align} u(u\cdot v) &=\left(uu^T\right)v\\ &=Z_uv\tag{2} \end{align} $$

The orthogonal projection of $v$ onto the plane perpendicular to $u$ is given by subtracting the orthogonal projection of $v$ onto $u$ from $v$: $$ \begin{align} v-u(u\cdot v) &=\left(I-uu^T\right)v\\ &=X_uv\tag{3} \end{align} $$ Thus, rotating $v$ by angle $\theta$ around $u$ would be given by $$ \left(Z_u+\sin(\theta)Y_u+\cos(\theta)X_u\right)v\tag{4} $$ Since $X_u+Z_u=I$, the rotation matrix in $(4)$ can be rewritten as $$ I+\sin(\theta)Y_u-(1-\cos(\theta))X_u\tag{5} $$ where the matrices $X_u$ and $Y_u$ are given in $(3)$ and $(1)$ above.

robjohn
  • 353,833