E5 Matrix Assignment 1 - 2009

Contents

The  original MatLab file is here (E5MatAsn1.m)..

Problem 1:

In this problem, and subsequent problems, the original point is shown with a thin line, the transformed point (after the matrix multiplication) is shown by a thick line.

theta=45 * pi/180;
A=[cos(theta) sin(-theta); sin(theta) cos(theta)];
xy=[1 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation);
plot([0 xy(1)],[0 xy(2)],'b-');  hold on;
plot(xy(1),xy(2),'bo');
plot([0 xyp(1)],[0 xyp(2)],'b-','Linewidth',3);
plot(xyp(1),xyp(2),'bo');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 1, rotation by 45deg')

Problem 2:

theta=-90 * pi/180;
A=[cos(theta) sin(-theta); sin(theta) cos(theta)];
xy=[-1 -2]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation);
plot([0 xy(1)],[0 xy(2)],'r--');  hold on;
plot(xy(1),xy(2),'rd');
plot([0 xyp(1)],[0 xyp(2)],'r--','Linewidth',3);
plot(xyp(1),xyp(2),'rd');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 2, rotation by -90deg')

Problem 3:

theta=45 * pi/180;
A=[cos(theta) sin(-theta) 0;
   sin(theta) cos(theta) 0;
   0 0 1];
xy=[1 1 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation);
plot([0 xy(1)],[0 xy(2)],'b-');  hold on;
plot(xy(1),xy(2),'bo');
plot([0 xyp(1)],[0 xyp(2)],'b-','Linewidth',3);
plot(xyp(1),xyp(2),'bo');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 3, rotation by 45deg')

Problem 4:

theta=-90 * pi/180;
A=[cos(theta) sin(-theta) 0;
   sin(theta) cos(theta) 0;
   0 0 1];
xy=[-1 -2 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation);
plot([0 xy(1)],[0 xy(2)],'r--');  hold on;
plot(xy(1),xy(2),'rd');
plot([0 xyp(1)],[0 xyp(2)],'r--','Linewidth',3);
plot(xyp(1),xyp(2),'rd');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 4, rotation by -90deg')

Problem 5:

tx=1;  ty=-2;
A=[1 0 tx;     0 1 ty;     0 0 1];
xy=[1 1 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after translation);
plot([0 xy(1)],[0 xy(2)],'b-');  hold on;
plot(xy(1),xy(2),'bo');
plot([0 xyp(1)],[0 xyp(2)],'b-','Linewidth',3);
plot(xyp(1),xyp(2),'bo');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 5, translation by (1,-2)')

Problem 6:

tx=1;  ty=1;
A=[1 0 tx;     0 1 ty;     0 0 1];
xy=[-1 -2 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after translation);
plot([0 xy(1)],[0 xy(2)],'r--');  hold on;
plot(xy(1),xy(2),'rd');
plot([0 xyp(1)],[0 xyp(2)],'r--','Linewidth',3);
plot(xyp(1),xyp(2),'rd');
hold off;
axis([-3 3 -3 3]); grid;  title('Problem 6 (as intended), translation by (1,1)')

Problem 7:

tx=1;  ty=-2; theta=45 * pi/180;
A=[cos(theta) sin(-theta) tx;
   sin(theta) cos(theta) ty;
   0 0 1];
xy=[1 1 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation and translation);
plot([0 xy(1)],[0 xy(2)],'b-');  hold on;
plot(xy(1),xy(2),'bo');
plot([0 xyp(1)],[0 xyp(2)],'b-','Linewidth',3);
plot(xyp(1),xyp(2),'bo');
hold off;
axis([-3 3 -3 3]); grid;
title('Problem 7, rotation by 45deg, translation (1,-2)')

Problem 8:

tx=1;  ty=1;  theta=-90 * pi/180;
A=[cos(theta) sin(-theta) tx;
   sin(theta) cos(theta) ty;
   0 0 1];
xy=[-1 -2 1]';  %xy(1)=x;   xy(2)=y;
xyp=A*xy;

%Plot point (before and after rotation and translation);
plot([0 xy(1,1)],[0 xy(2,1)],'b-');  hold on;
plot([0 xy(1)],[0 xy(2)],'r--');  hold on;
plot(xy(1),xy(2),'rd');
plot([0 xyp(1)],[0 xyp(2)],'r--','Linewidth',3);
plot(xyp(1),xyp(2),'rd');
hold off;
axis([-3 3 -3 3]); grid;
title('Problem 8, rotation by -90deg, translation by (1,1)')

Problem 9:

Theta is the angle of rotation. tx is the translation (after rotation) of the point in the x direction. ty is the translation (after rotation) of the point in the y direction.

Problem 10

tx=0;  ty=0;  theta=45 * pi/180;
A=[cos(theta) sin(-theta) tx;
   sin(theta) cos(theta) ty;
   0 0 1];
xy=[1 -1;
    1 -2;
    1 1];   %first column is for x1,y1 second for x2,y2;
xyp=A*xy;

%Plot first point (before and after rotation and translation);
plot([0 xy(1,1)],[0 xy(2,1)],'b-');  hold on;
plot(xy(1),xy(2),'bo');
plot([0 xyp(1,1)],[0 xyp(2,1)],'b-','Linewidth',3);
plot([0 xyp(1,1)],[0 xyp(2,1)],'bo');

%Plot second point (before and after rotation and translation);
plot([0 xy(1,2)],[0 xy(2,2)],'r:');  hold on;
plot(xy(1,2),xy(2,2),'rd');
plot([0 xyp(1,2)],[0 xyp(2,2)],'r:','Linewidth',3);
plot([0 xyp(1,2)],[0 xyp(2,2)],'rd');

hold off;
axis([-3 3 -3 3]); grid;
title('Problem 10, multiple points, rotation 45^\circ, no translation')