function R = CS5320_gen_R(u,theta)
% CS5320_gen_R - generate a rotation matrix about an arbitrary vector
% On input:
%     u (3x1 vector): unit vector about which to rotate
%     theta (float): amount to rotate (in radians)
% On output:
%     R (3x3 matrix): rotation matrix
% Call:
%     R = CS5320_gen_R([0;0;1],pi/2);
% Author:
%     T. Henderson
%     UU
%     Spring 2016
%

R = zeros(3,3);
u = u/norm(u);
ux = u(1);
uy = u(2);
uz = u(3);
cos_t = cos(theta);
sin_t = sin(theta);
one_cos = 1 - cos_t;

R(1,1) = cos_t + ux^2*one_cos;
R(1,2) = ux*uy*one_cos - uz*sin_t;
R(1,3) = ux*uz*one_cos + uy*sin_t;
R(2,1) = uy*ux*one_cos + uz*sin_t;
R(2,2) = cos_t + uy^2*one_cos;
R(2,3) = uy*uz*one_cos - ux*sin_t;
R(3,1) = uz*ux*one_cos - uy*sin_t;
R(3,2) = uz*uy*one_cos + ux*sin_t;
R(3,3) = cos_t + uz^2*one_cos;
