% see the effect of a rotation matrix on a set of vectors

% six random vectors 
x = -5+10*rand(2,6);

% a unit square
x = [0 1 1 0;0 0 1 1];

% moving the square around
x = x-1.25*ones(size(x));

% a suitable axis
ax = [-1,1,-1,1]*2;

% create a new figure and close all previous
close all; figure;

% a rotation matrix, where the angle is passed in 
r =@(t) [cos(t) sin(t);-sin(t) cos(t)];
%r =@(t) [.5 .75; -3/5 11/10];

% a positive rotation by pi/12 radians
t = pi/5; 

% a projection matrix
P = @(r) [cos(r)^2 sin(r)*cos(r); sin(r)*cos(r) sin(r)^2];

% display 100 successive rotations
colors = {'r','g','b','c','m','y','k','w'};
colors = {'r','g'}

for i=1:300;
		% plot the vector, setting the current plot to h
		h = PlotVector(x,ax,'r');
		g = fill(x(1,:),x(2,:),colors{mod(i,length(colors))+1})

		% projection stuff
		%y = P(pi/4)*x;
		%g = PlotVector(y,ax,'k');

		% pause so we can see, then delete the current plot, and move on
		pause(.001); delete(h); %delete(g);
		

		% rotate the current set of vectors
		x = r(t)*x ; 
end;
