function [Y]=ptrans(X,tt,first_oper)

%PUBLISHED UNDER THE CREATIVE COMMONS LICENSE (SEE MY WEBPAGE FOR MORE DETAILS)

% ------------------------------------------------------------- %
% THIS VERSION OF PTRANS WORKS ONLY WITH RIGID TRANSFORMATIONS %
% ------------------------------------------------------------- %
%
%X: POINT SET TO BE TRANSFORMED
%
%tt: TRANSFORMATION PARAMETERS (VECTOR !!!)
%  tt(1): ROTATION (DEGREES !!!)
%  tt(2): TRANSLATION - Tx
%  tt(3): TRANSLATION - Ty
%
%first_oper: DETERMINE WHICH OPERATION (['ROTATION'] OR 'TRANSLATION')
%            WILL BE DONE FIRST.


if nargin == 2
    first_oper='ROTATION';
end
tt(1) = tt(1) * 0.0174532925; %CONVERT ANGLE TO RADS
if length(tt) == 1
    tt = [tt(1); 0; 0];
elseif length(tt) == 2
    tt = [tt(1); tt(2); 0];
end

C = cos(tt(1)); S = sin(tt(1));
R = [C S; -S C];



% IMPORTANT !!!!!!
% Xg = mean(X)'; % ROTATION BASED ON THE CENTER OF THE SCENE
Xg = [0; 0];
% -



Y = zeros (size(X));
if strcmp (first_oper,'ROTATION')
    for i=1:size(X,1)
        Y (i,:) = R * (X(i,:)' - Xg) + (tt(2:3) + Xg);
    end
elseif strcmp (first_oper,'TRANSLATION')
    for i=1:size(X,1)
        Y (i,:) = R * (X(i,:)' - Xg + tt(2:3))  + Xg;
    end    
else
    error (sprintf ('%s: unknown operation.',first_oper));
end