function T = cv_genT(ax,ay,az,tx,ty,tz)
%
% cv_genT - generate a 4x4 transform matrix from XYZ angles and translation
% Call: T = cv_genT(ax,ay,az,tx,ty,tz)
% On input:
%     ax: angle of rotation about fixed X axis
%     ay: angle of rotation about fixed Y axis
%     az: angle of rotation about fixed Z axis
%     tx: x translation amount
%     ty: y translation amount
%     tz: z translation amount
% On output:
%     T: 4x4 transform matrix
% Author:
%     Tom Henderson
%     7 January 1999
% Custom Functions Used:
%     none
% Method:
%     build rotation matrix as upper left 3x3 corner of T; put column 4 as
% [tx ty tz 1]', and fill in row 4 as [0 0 0 1]
% Testing:
%  
%>> T = cv_genT(0,0,pi/2,1,2,-3)
%
% T =
%
%    0.9996   -0.0274         0    1.0000
%    0.0274    0.9996         0    2.0000
%         0         0    1.0000   -3.0000
%         0         0         0    1.0000
%
% >> 
%

rx = pi*ax/180;
ry = pi*ay/180;
rz = pi*az/180;

T1 = [1 0 0 0; 0 cos(rx) -sin(rx) 0; 0 sin(rx) cos(rx) 0; 0 0 0 1];
T2 = [cos(ry) 0 sin(ry) 0; 0 1 0 0; -sin(ry) 0 cos(ry) 0; 0 0 0 1];
T3 = [cos(rz) -sin(rz) 0 0; sin(rz) cos(rz) 0 0; 0 0 1 0; 0 0 0 1];

T = T1*T2*T3;
T(:,4) = [tx ty tz 1]';
