function [PP] = Rotate(P,theta,index)
% function [PP] = Rotate(P,theta,index)
% Rotate a point (x,y,z) at the angle theta counter-clockwise
% about x-axis, if index = 1, about y-axis, if index = 2, and about z-axis, if index = 3
% P - coordinate matrix of an old view, PP = R*P - a new coordinate matrix of a new view

[m,n] = size(P); % m = 3 for all examples

if (index == 1)
    R = [ 1, 0, 0; 0, cos(theta), -sin(theta); 0, sin(theta),cos(theta)];
elseif (index == 2)
    R = [ cos(theta), 0, sin(theta); 0, 1, 0; -sin(theta),0,cos(theta)];
elseif (index == 3)
    R = [ cos(theta), -sin(theta), 0; sin(theta), cos(theta), 0; 0, 0, 1];
else
    disp('ERROR: index must be equal to 1,2,or 3!');
end
        
PP = R*P;