Some notes on axis angle rotation
To build some intuition (hopefully and not confuse more than help ..) the approach is to first show how you can rotate a vector v in 2D vector arithmetic and then rearrange it into a matrix. (The math behind it is that vector arithmetic is a linear transformation and matrices are linear transformations as well, so we start with vectors. See Khan Academy - Linear algebra course ).
And then how to rotate a 3D vector with vector arithmetic and then rearrange over to a 3D rotation matrix (which rotates a vector v around an given axis).
The tex file is written with pytex so it's a bit annoying to compile. That is why I added the pdf and rendered a png in the readme:
The 3D rotation formula is similar to that used in Ravi Ramamoorthi's course (matrix part). Also Mathomas videos are a nice resource on this topic.
An (inefficient) implementation in python and numpy could look like:
import numpy as np
# input: normalized rotation axis vector n, angle theta (radians)
# output: 3x3 rotation matrix
def axis_angle_rotation(n, theta):
def skew(n): # skew symmetric matrix for cross product with n: n x v = skew(n) x v
# transform all basis column vectors ( n x e1, n x e2, n x e3 )
return np.column_stack( (np.cross(n, e) for e in np.eye(3)) )
P = np.outer(n, n) # outer product of n with n (nn^T) is a matrix
I = np.identity(3)
K = skew(n)
return P + np.cos(theta) * (I - P) + np.sin(theta) * K
Hope it helps :-)