Uploaded by ankursaini619

Assignment1.m

advertisement
clc
clear all
close all
Ax=6;
Ay=1;
Bx=8;
By=1;
Cx=10;
Cy=4;
Dx=3;
Dy=4;
plot([Ax,Bx],[Ay,By],'b')
hold on
plot([Bx,Cx],[By,Cy],'b')
hold on
plot([Cx,Dx],[Cy,Dy],'b')
hold on
plot([Dx,Ax],[Dy,Ay],'b')
hold on
Aold=[Ax;Ay;1];
Bold=[Bx;By;1];
Cold=[Cx;Cy;1];
Dold=[Dx;Dy;1];
Oldpos=[Aold,Bold,Cold,Dold];
NewPos= trans2d(1,Oldpos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
plot([Axnew,Bxnew],[Aynew,Bynew],'r') % Line between point A and B
hold on
% To hold figure handle on same figure
plot([Bxnew,Cxnew],[Bynew,Cynew],'r') % Line between point B and C
hold on
plot([Cxnew,Dxnew],[Cynew,Dynew],'r') % Line between point C and D
hold on
plot([Dxnew,Axnew],[Dynew,Aynew],'r') % Line between point D and A
hold on
Oldpos=NewPos;
NewPos= trans2d(2,Oldpos);
% OldPos = NewPos;
% NewPos= trans2d(3,OldPos);
% OldPos = NewPos;
% NewPos= trans2d(2,OldPos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
% Plotting New Position of the Rectangle
plot([Axnew,Bxnew],[Aynew,Bynew],'k') % Line between
%axis([-10 20 -10 20])
hold on % To hold figure handle on same figure
plot([Bxnew,Cxnew],[Bynew,Cynew],'k') % Line between
hold on
plot([Cxnew,Dxnew],[Cynew,Dynew],'k') % Line between
hold on
plot([Dxnew,Axnew],[Dynew,Aynew],'k') % Line between
hold on;
Oldpos=NewPos;
NewPos= trans2d(3,Oldpos);
% OldPos = NewPos;
% NewPos= trans2d(3,OldPos);
% OldPos = NewPos;
% NewPos= trans2d(2,OldPos);
Axnew = NewPos(1,1);
Aynew = NewPos(2,1);
Bxnew = NewPos(1,2);
Bynew = NewPos(2,2);
Cxnew = NewPos(1,3);
Cynew = NewPos(2,3);
Dxnew = NewPos(1,4);
Dynew = NewPos(2,4);
% Plotting New Position of the Rectangle
plot([Axnew,Bxnew],[Aynew,Bynew],'g') % Line between
axis([-10 20 -10 20])
hold on % To hold figure handle on same figure
plot([Bxnew,Cxnew],[Bynew,Cynew],'g') % Line between
hold on
plot([Cxnew,Dxnew],[Cynew,Dynew],'g') % Line between
hold on
plot([Dxnew,Axnew],[Dynew,Aynew],'g') % Line between
hold on;
function [newpoint] = trans2d(type,oldpoint)
if type==1 % Translation
p = 5;
q = 5;
TRANS = [1 0 p;...
0 1 q;...
0 0 1];
MAT = TRANS;
elseif type==2 % Rotation
theta = 90;
ROT = [cosd(theta) -sind(theta) 0;...
sind(theta) cosd(theta) 0;...
0 0 1];
MAT = ROT;
point A and B
point B and C
point C and D
point D and A
point A and B
point B and C
point C and D
point D and A
elseif type==3 % Shear in y direction
REF= [-1 0 0;...
0 1 0;...
0 0 1];
MAT = REF;
end
newpoint = MAT*oldpoint;
end
Download