Question: ***In MATLAB*** please do the following questions: 6. Modify the M-file in EXAMPLE 8 adding translations that bring the square to its original position using

***In MATLAB*** please do the following questions:

***In MATLAB*** please do the following questions: 6. Modify the M-file in

EXAMPLE 8 adding translations that bring the square to its original position

using 20 iterations and a single additional for loop (for a total

of three loops). Include the M-file. You do not need to include

6. Modify the M-file in EXAMPLE 8 adding translations that bring the square to its original position using 20 iterations and a single additional for loop (for a total of three loops). Include the M-file. You do not need to include the figure. EXAMPLE 8 Consider the matrix S representing the original square in homogeneous coordinates. In the following M-file we translate the square horizontally using c = 0.4 and C2 = 0 for 20 times. We then translate the square vertically using c = 0 and C2 = 0.4 and 20 iterations. clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1); % square in homogeneous coordinates M1 = [1,0,0.4;0,1,0;0,0,1); % first translation matrix M2 = [1,0,0,0,1,0.4;0,0,1); % the second translation matrix p = plot (S(1,:),(2,:)); % plot the original square axis square, axis ([-1,10,-1,10]), grid on for i = 1:20 S = M1+S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the translated square pause (0.1) end for i = 1:20 S=M2 S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',S(2,:)); % plot the translated square pause (0.1) end 7. Consider the square in EXAMPLE 9. The goal of this exercise is to bring back the square to its original position by first translating it horizontally to the left 8 units using 20 iterations, and then rotating it counterclockwise */2 radians around the point (1,0) using 6 iterations. This can be done by modifying the code in EXAMPLE 9 by adding two for loops. The first loop should translate the square while the second should rotate it around the point (1,0). Note that the rotation is counterclockwise, while in EXAMPLE 9 it was clockwise. Include the M-file. You do not need to include the figure. EXAMPLE 9 In this example we first translate the square horizontally 8 units using increments of 0.4. We then rotate the resulting square clockwise 7/2 radians around the vertex (9,0) using increments of /12 radians. clf S=[0,1,1,0,0,0,0,1,1,0;1,1,1,1,1); % square in homogeneous coordinates M1 = [1,0,0.4;0,1,0,0,0,1); % first translation matrix theta - pi/12; % define the angle theta Q=[cos (theta),-sin(theta),0; sin(theta), cos(theta),0,0,0,1); % rotation matrix about (0,0) QP=[1,0,9;0,1,0,0,0,1]*Q'*[1,0,-9;0,1,0;0,0,1); % rotation matrix about (9,0) P = plot (S(1,:),(2,:)); % plot the original square axis equal, axis ((-0.5,11, -2,5]), grid on for i = 1:20 S = M1*S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the translated square pause (0.1) end for i = 1:6 SEQP+S; % compute the rotated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the rotated square pause (0.1) end 6. Modify the M-file in EXAMPLE 8 adding translations that bring the square to its original position using 20 iterations and a single additional for loop (for a total of three loops). Include the M-file. You do not need to include the figure. EXAMPLE 8 Consider the matrix S representing the original square in homogeneous coordinates. In the following M-file we translate the square horizontally using c = 0.4 and C2 = 0 for 20 times. We then translate the square vertically using c = 0 and C2 = 0.4 and 20 iterations. clf S=[0,1,1,0,0;0,0,1,1,0;1,1,1,1,1); % square in homogeneous coordinates M1 = [1,0,0.4;0,1,0;0,0,1); % first translation matrix M2 = [1,0,0,0,1,0.4;0,0,1); % the second translation matrix p = plot (S(1,:),(2,:)); % plot the original square axis square, axis ([-1,10,-1,10]), grid on for i = 1:20 S = M1+S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the translated square pause (0.1) end for i = 1:20 S=M2 S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',S(2,:)); % plot the translated square pause (0.1) end 7. Consider the square in EXAMPLE 9. The goal of this exercise is to bring back the square to its original position by first translating it horizontally to the left 8 units using 20 iterations, and then rotating it counterclockwise */2 radians around the point (1,0) using 6 iterations. This can be done by modifying the code in EXAMPLE 9 by adding two for loops. The first loop should translate the square while the second should rotate it around the point (1,0). Note that the rotation is counterclockwise, while in EXAMPLE 9 it was clockwise. Include the M-file. You do not need to include the figure. EXAMPLE 9 In this example we first translate the square horizontally 8 units using increments of 0.4. We then rotate the resulting square clockwise 7/2 radians around the vertex (9,0) using increments of /12 radians. clf S=[0,1,1,0,0,0,0,1,1,0;1,1,1,1,1); % square in homogeneous coordinates M1 = [1,0,0.4;0,1,0,0,0,1); % first translation matrix theta - pi/12; % define the angle theta Q=[cos (theta),-sin(theta),0; sin(theta), cos(theta),0,0,0,1); % rotation matrix about (0,0) QP=[1,0,9;0,1,0,0,0,1]*Q'*[1,0,-9;0,1,0;0,0,1); % rotation matrix about (9,0) P = plot (S(1,:),(2,:)); % plot the original square axis equal, axis ((-0.5,11, -2,5]), grid on for i = 1:20 S = M1*S; % compute the translated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the translated square pause (0.1) end for i = 1:6 SEQP+S; % compute the rotated square set(p, 'xdata',S(1,:), 'ydata',s(2,:)); % plot the rotated square pause (0.1) end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!