% file rot_refl_2d
%
% given line from [0 0]' to [3 2]'
% rotate 90 degrees CCW
% reflect about y axis
% reflect about x axis

clear all; close all;

P=[0 0]'; % transpose, since P is a column vector in pre-multiply convention
Q=[3 2]';

% P and Q are vertices of a simple object (a line with two endpoints)
% each vertex of the object is a column vector
% in this case, the object is a line with only two vertices
% the object is represented by a matrix
line=[P(1) Q(1);
      P(2) Q(2)];
% the first row is the x-components of the object, 2nd row is y-components 
  
  
% rotate CCW 90 degrees
% T1 = [ cos 90 -sin 90; 
%        sin 90  cos 90];

T1 = [0 -1;
      1  0];
  
line2 = T1*line;

% reflect about x axis

T2 = [1 0;
      0 -1];
  
  line3 = T2*line2;
  
  % reflect about y axis
  
  T3 = [-1 0;
         0 1];
     
  line4 = T3*line3;
  
  hold on
  plot(line(1,:),line(2,:),'mo-');
  plot(line2(1,:),line2(2,:),'bo-');
  plot(line3(1,:),line3(2,:),'co-');
  plot(line4(1,:),line4(2,:),'go-');
  %plot(x-components, y-components,'linespec')
  % x-components are 1st row of the matrix line
  % colors m magenta, b blue, c cyan, g green, y yellow, r red, k black
  % search for 'linespec' in Matlab help window
  % 'b0-' means blue line, circles at end points, solid line
  axis([-3 3 -3 3]); % axis([xmin xmax ymin ymax]); 
  axis equal; % equal scale in both x and y
  plot([-3 3],[0 0],'k'); % plot x-axis in solid black (optional)
  plot([0 0],[-3 3],'k'); % plot y-axis in solid black (optional)
  xlabel('x');ylabel('y');
  title('rotate 90 CCW, reflect x axis, reflect y axis');
  grid on;
  hold off;