% LAB_13: 2016-07-15
% EXCEL EA-1
clear
clc
close all
format compact
shape = [0 3 3 1 1 0; % x coordinates of points
0 0 1 1 2 2; % y coordinates of points
1 1 1 1 1 1]; % one in the last row
%% Drawing the polygon
clf % clear the current figure
fill(shape(1, :), shape(2, :), 'b') % Draw the polygon given by "shape"
axis([-10, 10, -10, 10]) % Set axis limits
axis square % make x- and y-axes equal
%% Scaling the polygon
clf
% Create a scaling matrix to stretch the shape by a factor of 2 in the x
% direction and 3 in the y direction
U = [2 0 0; 0 3 0; 0 0 1];
% Multiply the shape matrix by the scaling matrix
shape_2 = U*shape;
fill(shape_2(1, :), shape_2(2, :), 'b') % Draw the polygon given by "shape"
axis([-10, 10, -10, 10]) % Set axis limits
axis square % make x- and y-axes equal
%% Rotating the polygon
clf
% Create a rotation matrix to rotate counterclockwise by 90 degrees
%R = ...
% Mulitply the shape matrix by the rotation matrix
%shape_2 = ...
fill(shape_2(1, :), shape_2(2, :), 'b') % Draw the polygon given by "shape"
axis([-10, 10, -10, 10]) % Set axis limits
axis square % make x- and y-axes equal
%% Shearing the polygon
clf
% Create a shear matrix to apply a 50% shear in the x direction
%H = ...
% Mulitply the shape matrix by the shear matrix
%shape_2 = ...
fill(shape_2(1, :), shape_2(2, :), 'b') % Draw the polygon given by "shape"
axis([-10, 10, -10, 10]) % Set axis limits
axis square % make x- and y-axes equal
%% Translating the polygon
clf
% Create a translation matrix to shift right 2 units and up 3 units
%T = ...
% Mulitply the shape matrix by the translation matrix
%shape_2 = ...
fill(shape_2(1, :), shape_2(2, :), 'b') % Draw the polygon given by "shape"
axis([-10 10 -10 10]) % Set axis limits
axis square % make x- and y-axes equal
%% Try combining transformations
clf
% Create a translation matrix
%T = ...
% Create a rotation matrix
%R = ...
% Multiply the shape matrix by the translation matrix and the rotation
% matrix. Does the order matter?
%shape_2 = ...
fill(shape_2(1, :), shape_2(2, :), 'b') % Draw the polygon given by "shape"
axis([-10, 10, -10, 10]) % Set axis limits
axis square % make x- and y-axes equal