ASSIGNMENT NO 6
2D Transformations
MT22CDM012
M.NAVEEN KUMAR
Q. Code for Translation, Scaling, Reflection and Rotation
1) Translation function code
function [x,y] = Translation(x0,y0,h,k);
x = x0 + h;
y = y0 + k;
end
2) Scaling function code
function [x,y] = Scaling(x0,y0,Sx,Sy);
x = x0 * Sx;
y = y0 * Sy;
end
3) Reflection function code
function [x,y] = Reflection(about,x0,y0);
if(about == 'x')
x = x0;
y = (-1) * y0;
end
if(about == 'y')
x = (-1) * x0;
y = y0;
end
if(about == 'o')
x = (-1) * x0;
y = (-1) * y0;
end
4) Rotation function code
function [x,y] = Rotation(angle,x0,y0);
% angle is positive for counterclockwise
x = x0*cos(angle) - y0*sin(angle);
y = x0*sin(angle) + y0*cos(angle);
5) Main function code
x1 = input("Enter x coordinate of first point");
y1 = input("Enter y coordinate of first point");
x2 = input("Enter x coordinate of second point");
y2 = input("Enter y coordinate of second point");
x3 = input("Enter x coordinate of third point");
y3 = input("Enter y coordinate of third point");
%Translating system about x axis by 5 and about y axis by 8
[x1,y1] = Translation(x1,y1,5,8);
[x2,y2] = Translation(x2,y2,5,8);
[x3,y3] = Translation(x3,y3,5,8);
%Scaling factor 3 about x axis and 4 about y axis
[x1,y1] = Scaling(x1,y1,3,4);
[x2,y2] = Scaling(x2,y2,3,4);
[x3,y3] = Scaling(x3,y3,3,4);
%Reflection about y axis
[x1,y1] = Reflection('y',x1,y1);
[x2,y2] = Reflection('y',x2,y2);
[x3,y3] = Reflection('y',x3,y3);
%Rotation by 30 degrees counterclockwise
[x1,y1] = Rotation(30,x1,y1);
[x2,y2] = Rotation(30,x2,y2);
[x3,y3] = Rotation(30,x3,y3);
disp("New coordinates of triangle are:");
Output in command window