% file rot2d_0.m
% ENGR 150 exercise
% reflect point around line
% 2-D to start
% newpoint = composite transformation T * givenpoint (pre-multiply method)

% =======================================
% MATLAB HELP
% to learn more about Matlab, type 'intro'
% (without quotes) at the command prompt
% also type 'demo' for more complete intro
% for help on any function, type 'helpwin functionname'
% for help on syntax:
% type 'helpwin punct' 'helpwin ops'  'helpwin arith'
% 'helpwin colon'
% for web-based help, type 'helpdesk'
% keyword search, type 'lookfor keyword'
% type variable names to get their values
% =========================================

% inputs: givenpoint (x,y) and
% lines y=0 or x=0 or y=x or y=-x
% output: reflected point

% enter inputs

vertex_matrix=[4 5 4 4; 1 2 3 1];% [x-coords; y-coords]

givenpoint=vertex_matrix;
% givenpoint is a matrix which represents 4 points (4,1)(5,2)(4,3)(4,1)
% givenpoint row 1 = x-coords, row2 = y-coords

% start transformation

 % T1: reflect about x-axis
 T1=[ 1  0;
      0 -1];

  reflectedpoint = T1*givenpoint;
% reflected about x-axis
 
 % T2: reflect about y=-x
 T2=[0 -1; 
    -1 0];  

 % composite transformation
 Tcomp=T2*T1; 
 
 % compute new point
 newpoint=Tcomp*givenpoint;  
            
 % plot line and points              
 hold on;
 % colors b g r y m c w k
 plot([-9 9],[0 0],'b-');% x-axis
 plot([-9 9],[9 -9],'b-'); % y=-x
 plot(givenpoint(1,:),givenpoint(2,:),'r-');   
     %givenpoint(1,:) is row 1 = x-coords of givenpoint
     %givenpoint(2,:) is row 2 = y-coords of givenpoint
 plot(reflectedpoint(1,:),reflectedpoint(2,:),'m-');     
 plot(newpoint(1,:),newpoint(2,:),'g-');
 axis equal;
 xlabel('x');ylabel('y');
 title('Reflect point about line');
 hold off;
 
