You are on page 1of 4

function [newpoint] = trans2d(type,oldpoint

if type == 1 % Translation

p = 2;

q = 2;

TRANS = [1 0 p;…

0 1 q;…

0 0 1];

MAT = TRANS;

elseif type == 2 % Rotation

theta = 45;

ROT = [cosd(theta) -sind(theta) 0;…

sind(theta) cosd(theta) 0;…

0 0 1];

MAT = ROT;

elseif type == 3 % Shear in y direction

shy = 1.5;

SHEARY = [1 0 0;…

shy 1 0;…

0 0 1];

MAT = SHEARY;

end

newpoint = MAT*oldpoint;

end

clc % To clear the screen

clear all % To clear all the variables from workspace

close all % To close all the figure windows

% Initial Position of Rectangle

Ax = 3; % X Coordinate of point A
Ay = 1; % Y Coordinate of point A

Bx = 3; % X Coordinate of point B

By = 4; % Y Coordinate of point B

Cx = 8; % X Coordinate of point C

Cy = 4; % Y Coordinate of point C

Dx = 8; % X Coordinate of point D

Dy = 1; % Y Coordinate of point D

% Plot Initial Position of Rectangle

plot ([Ax,Bx] , [Ay,By] , ‘b’) % Line between point A and B

axis ([-10 20 -10 20])

hold on % To hold figure handle on same figure

plot ([Bx,Cx] , [By,Cy] , ‘b’) % Line between point B and C

hold on

plot ([Cx,Dx] , [Cy,Dy], ‘b’) % Line between point C and D

hold on

plot ([Cx,Dx] , [Cy,Dy], ‘b’) % Line between point D and A

hold on

% Transformation of all points of rectangle

% Tutorial 1(a)

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);

%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],’r’) % Line between point A and B

%axis ([-10 20 10 20])

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 C and D


hold on

You might also like