function [Pr]=rotoTranslation(P, T, ang, Pts, varargin)
% This function performs the
% roto-translation of a polygon 
% whose coordinates are stored 
% in the matrix P 
%
% Stefano De Marchi, Dec. 2009
% ----------------------------
% P = n x 2 matrix 
%     P=[x1 y1
%        x2 y2]
%        ....
%        xn yn]
%
% T = translation vector
%
% ang = rotation angle
%
% Pts = point around which rotation
%       take place
%-----------------------------
% Pr = P after roto-translation
% --------------------- ------
n=max(size(P));
if nargin==3
   B=1/(n-1)*[sum(P(1:n-1,1)) sum(P(1:n-1,2))]; %barycenter
else
   B=Pts;
end
B1=B(1,1)+i*B(1,2);
BT=repmat(B1,n,1);
PC=P(:,1)+i*P(:,2);
PC=PC-BT;
PC=exp(i*ang)*PC;

T1=T(1,1)+i*T(1,2);
TT=repmat(T1,n,1);
PC=PC+TT;
Pr=[real(PC),imag(PC)];


 return
 