% MATLAB script for testing the correct computation of the matrix
% representation of a rotation with respect to the Cartesian basis.

% Generate random axis vectors and angles
a = rand(3,1); phi = rand(1,1);

% Compute rotation matrix
M = rotmatrix(a,phi);

% Check whether it is orthogonal
M*M',

% Check whether the axis is mapped to itself
norm(M*a-a),

% Check whether the angle is correct
x = rand(3,1); nx = norm(x); 
% project x onto the axis
px = a*dot(a,x)/norm(a)^2;
dot(M*x-px,x-px)/(norm(x-px)^2) - cos(phi),