0% found this document useful (0 votes)
38 views2 pages

MATLAB Code:: All All X 'x1 ' 'Y1 ' 'x2 ' 'Y2 '

This MATLAB code takes in user inputs to define two points, and allows the user to apply a sequence of rotation, translation, and scaling transformations to plot the transformed points. It first defines the initial points, gets the transformation parameters from the user, and plots the initial line between the points. It then sets up transformation matrices for rotation, translation, and scaling. Based on the transformation sequence entered by the user, it applies the appropriate sequence of transformations to the initial points and plots the transformed line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

MATLAB Code:: All All X 'x1 ' 'Y1 ' 'x2 ' 'Y2 '

This MATLAB code takes in user inputs to define two points, and allows the user to apply a sequence of rotation, translation, and scaling transformations to plot the transformed points. It first defines the initial points, gets the transformation parameters from the user, and plots the initial line between the points. It then sets up transformation matrices for rotation, translation, and scaling. Based on the transformation sequence entered by the user, it applies the appropriate sequence of transformations to the initial points and plots the transformed line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MATLAB code:

clc
close all
clear all
syms x
x1=input('x1=');
y1=input('y1=');
x2=input('x2=');
y2=input('y2=');
x=linspace(x1,x2);
o=[x1;y1;1];
j=[x2;y2;1];
a=input('angle of rotation=');
a=a*(3.14159/180);
tx=input('tx=');
ty=input('ty=');
sx=input('sx=');
sy=input('sy=');
fprintf('1.Rotation 2.Translation 3.Scaling\n')
seq= input('Enter sequence number row matrix=');
m=(y2-y1)/(x2-x1);
c=subs(y1-(m*x1));
y= m*x+c;
plot (x,y)
grid on
hold on
%%
syms X
b=[cos(a) -sin(a) 0; sin(a) cos(a) 0; 0 0 1];
g=[1 0 tx;0 1 ty;0 0 1];
sc=[sx 0 0;0 sy 0;0 0 1];
if seq==[1 2 3]
sol1=((sc*g)*b)*o;
sol2=((sc*g)*b)*j;
elseif seq==[1 3 2]
sol1=((g*sc)*b)*o;
sol2=((g*sc)*b)*j;
elseif seq==[3 1 2]
sol1=((g*b)*sc)*o;
sol2=((g*b)*sc)*j;
elseif seq==[2 1 3]
sol1=((sc*b)*g)*o;
sol2=((sc*b)*g)*j;
elseif seq==[2 3 1]
sol1=((b*sc)*g)*o;
sol2=((b*sc)*g)*j;
elseif seq==[3 2 1]
sol1=((b*g)*sc)*o;
sol2=((b*g)*sc)*j;
end
%%
X1=sol1(1,1);
Y1=sol1(2,1);
X2=sol2(1,1);
Y2=sol2(2,1);
X=linspace(X1,X2);
M=(Y2-Y1)/(X2-X1);
C=(Y1-(M*X1));
Y=M*X+C;
plot(X,Y)
grid on
hold on

You might also like