Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In MATLAB please do the following questions: *Please don't be one of those people again that copied other people's Chegg answer 6. Modify the M-file

In MATLAB please do the following questions:

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

*Please don't be one of those people again that copied other people's Chegg answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions