# Animation nodes: rotate around axis

How do you rotate an object around a given unit vector and angle? I thought I could use this matrix, but I'm unable to create a custom 3x3 matrix inside animation nodes.

$$R= \begin{bmatrix} \cos\theta+u_x^2(1-\cos\theta) & u_xu_y(1-\cos\theta)-u_z\sin\theta & u_xu_z(1-\cos\theta)+u_y\sin\theta\\ u_yu_x(1-\cos\theta)+u_z\sin\theta & \cos\theta+u_y^2(1-\cos\theta) & u_yu_z(1-\cos\theta)-u_x\sin\theta\\ u_zu_x(1-\cos\theta)-u_y\sin\theta & u_zu_y(1-\cos\theta)+u_x\sin\theta & \cos\theta+u_z^2(1-\cos\theta) \end{bmatrix}$$

You can use the Convert Rotation Types node to construct a rotation matrix from Axis Angle model and then use it to rotate the object:

• It doesn't look like it's 'rolling' around the axis though... Commented Dec 29, 2017 at 19:14
• @BertVdB May be you should choose one of the fundamental axis to see it clearer. Let me know if you still don't think it is the result you want. Commented Dec 29, 2017 at 19:19

I found a way to create a matrix like this using the script-subprogram method in animation nodes:

Node setup:

And the following script:

import bpy
from mathutils import Matrix

Rotation = Matrix.Rotation(angle, 4, axis)