function Q = vrrotvec2mat(r)
	% implementation of vrrotvec2mat
	% similar to the MATLAB Simulink 3D Animation toolbox
	%
	% returns a rotation matrix Q given an axis-angle representation r of the
	% rotation 
	%
	% input:	r			axis-angle rotation vector
	%			r(1:3)	unit vector of rotation
	%			r(4)		angle in radians to rotate
	% output:Q			rotation matrix
	
	% special case of null rotation
	if mod(r(4),2*pi) == 0 || norm(r(1:3)) == 0
		Q		= eye(3);
		return
	end
	
	u			= r(1:3) / norm(r(1:3));
	ucross	= [0, -u(3), u(2); u(3), 0, -u(1); -u(2), u(1), 0];
	uout		= u(:) * u(:)';
	Q			= cos(r(4))*eye(3) + sin(r(4))*ucross + (1-cos(r(4)))*uout;
end
