%TRANSSURF   Transform Surf
% Function transforms X Y Z matrices defining a parametric surface 
% according to the homogeneous transformation T.
%
% Syntax:  [Xt,Yt,Zt] = transSurf(T,X,Y,Z)
%
% Inputs:
%    T - transformation
%    (X, Y, Z) - matrices defining a parametric surface
%
% Outputs:
%    (Xt, Yt, Zt) - matrices defining a parametric surface after
%                   transformation

% Author: Travis Hydzik
% Last revision: 20 October 2004

function [Xt,Yt,Zt] = transSurf(T,X,Y,Z)

	[rows, cols]  = size(X);
	rc = rows*cols;
	
	X = reshape(X,1,rc);   % reshape X Y & Z to row vectors
	Y = reshape(Y,1,rc);
	Z = reshape(Z,1,rc);
	one = ones(1,rc);      % A long row vector of ones
    
	% Put vectors together to form positions in homogeneous coordinates.
	PTS = [ X
            Y
            Z
            one ];
                      
	PTS = T*PTS;
    
	% Extract the separate coordinates and reshape them back to their original shape.
	Xt = reshape(PTS(1,:),rows,cols);
	Yt = reshape(PTS(2,:),rows,cols);
	Zt = reshape(PTS(3,:),rows,cols);