%ROT   Rotation
% returns a 4x4 homogeneous transformation matrix describing the rotation about an arbitrary axis by angle theta.
%
% Syntax:  T = rot(axis,theta)
%
% Inputs:
%    axis - vector to rotate about
%    theta - angle to rotate
%
% Outputs:
%    T - homogeneous rotation transformation
%
% See also: ROTX, ROTY, ROTZ

% Author: Travis Hydzik
% Last revision: 20 October 2004

function T = rot(axis,theta)
	
    axis = axis/norm(axis);
		
    c = cos(theta);
    s = sin(theta);
    t = 1 - cos(theta);
     
    T = [ (t*axis(1)^2 + c)                (t*axis(1)*axis(2) - s*axis(3))  (t*axis(1)*axis(3) + s*axis(2))    0
          (t*axis(1)*axis(2) + s*axis(3))  (t*axis(2)^2 + c)                (t*axis(2)*axis(3) - s*axis(1))    0
          (t*axis(1)*axis(3) - s*axis(2))  (t*axis(2)*axis(3) + s*axis(1))  (t*axis(3)^2 + c)                  0
           0                                0                                0                                 1 ];