% Matlab Live Script document
% Demo ideas from Section 4.6 of textbook
% written by mike slattery, nov 2018

% Original polygon
shape = [1 2   3;
         1 2 1.5]
% Tranformation matrix
A = [2 0;
     0 1]
 
% New shape
shape2 = A*shape

% Plot both shapes
fig = axes();
hold on
plot(fig, shape(1,[1:end,1]), shape(2,[1:end,1]), 'g')
plot(fig, shape2(1,[1:end,1]), shape2(2,[1:end,1]), 'r')
fig.XAxisLocation = 'origin';
fig.XLimMode='manual';
fig.XLim=[-5,5];
fig.YAxisLocation = 'origin';
fig.YLimMode='manual';
fig.YLim=[-5,5];

%


%Exercise #4 on p.269
% Original polygon
shape = [1 2 2 1;
         0 0 3 3]
% Tranformation matrix
reflect_y = [1  0;
             0 -1];
shear_3 = [1 3;
           0 1];
A = shear_3*reflect_y
 
% New shape
shape2 = A*shape

% Plot both shapes
fig = axes();
hold on
plot(fig, shape(1,[1:end,1]), shape(2,[1:end,1]), 'g')
plot(fig, shape2(1,[1:end,1]), shape2(2,[1:end,1]), 'r')
fig.XAxisLocation = 'origin';
fig.XLimMode='manual';
fig.XLim=[-8,8];
fig.YAxisLocation = 'origin';
fig.YLimMode='manual';
fig.YLim=[-5,5];
inv(A)
A*A