function surf_affine= affine_surface(A, surf)
% Apply affine transform A to surface mesh surf
% A is 4x4 matrix. The surface vertices of surf_affine should be given by
%  p' = A p + c
%
%  (C) 2012. Moo K. Chung, Anqi Qiu   
% mkchung@wisc.edu
% University of Wisconsin-Madison
%
% Original: October 5, 2012
% Modified: October 7, 2012. Anqi simplied the code

p= surf.vertices';       %  p = 3 coordinates x n vertices
n=size(p,2);
pnew = [p; ones(1,n)];   % new codes by Anqi
pnew = A*pnew;
surf_affine.vertices = pnew(1:3,:)';
surf_affine.faces=surf.faces;

% OLD codes
%R=A(1:3,1:3);  % scaling and rotation matrix
%c= A(1:3,4); % translation
%pnew = (R*p)' + repmat(c,1,n)';
%surf_affine.vertices=pnew;




