An example: Let T=[0 1 1 0;0 1 -1 0], the same matrix as given
on Page 181. The following is a list of MatLab commands
which do the following.
- Plot the given triangle whose vertices are given in T.
- Stretch the triangle by 2, rotate it counterclockwise by
120 degrees and then plot the resulting triangle.
- Translate the triangle by the vector [1;2] and then plot
the resulting triangle.
- Reflect the triangle about the x-axis and then plot
the resulting triangle.
clf
tmat=[0 1 1 0;0 1 -1 0];
subplot(221),plot(tmat(1,:),tmat(2,:),'-')
subplot(221),axis([-5 5 -5 5])
text(0,0,'+')
title('original triangle')
axis square
%
tmat=2*tmat;
theta=2*pi/3;
rmat=[cos(theta) -sin(theta);sin(theta) cos(theta)];
tmat=rmat*tmat;
subplot(222),plot(tmat(1,:),tmat(2,:),'-')
subplot(222),axis([-5 5 -5 5])
text(0,0,'+')
title('dilation and rotation')
axis square
%
for i=1:4;
tmat(:,i)=tmat(:,i)+[1;2];
end;
subplot(223),plot(tmat(1,:),tmat(2,:),'-')
subplot(223),axis([-5 5 -5 5])
text(0,0,'+')
title('translation')
axis square
%
amat=[1 0;0 -1];
tmat=amat*tmat;
subplot(224),plot(tmat(1,:),tmat(2,:),'-')
subplot(224),axis([-5 5 -5 5])
text(0,0,'+')
title('reflection')
axis square
The graphs are given at the end of this assignment.
You may copy and paste above list into the notepad
and save it as a matLab file (with extension .m).
Run it in MatLab to see how it works.