Please provide solutions to 5a and 5b. Also please explain. Answer must be in MA
ID: 669327 • Letter: P
Question
Please provide solutions to 5a and 5b. Also please explain. Answer must be in MATLAB code.
6 MATLAB sessions: Laboratory 4 EXAMPLE 6 Consider the matrix T representing the triangle in the previous problems. In homogeneous coordinates the matrix becomes -0.5 0 0.5-0.5 In the following M-file we translate the triangle using c.1 and c2-1 for 20 times. We then translate the triangle horizontally using ci--.1 and c20 and 40 iterations. clf Tw [-0 . 5 ,0 , 0 . 5 ,-0 . 5 ;-1 , 1 ,-1 ,-1; 1 , 1 , 1 , 1); % define the triangle in homogeneous coordinates MI [1 ,0 , c 1:0, 1,c2:0,0,11; % define the first translation matrix M2· [1,0,-c1 ; 0,1,0:0,0,1] ; % define the second translation matrix p-plot (T(1, :),T(2, :)); % plot the original triangle axis([-7,7,-7,7) axis square figure(gcf) for i -1:20 T-M1*T; % compute the translated triangle set (p,'xdata ,,T(1, :) ,'ydata,,T(2, :)); % plot pause (0-1) the translated triangle end for i 1:40 TwM2*T; % compute the translated triangle set (p,'xdata ,,T(1, :),'ydata,,T(2, :)); % plot pause (0-1) the translated triangle end EXERCISES 5. (a) Modify the M-file in EXAMPLE 6 adding translations that bring the triangle to its original position using 20 iterations. (b) Write down a rotation matrix Q that rotates a vector in homogeneous coordinates /40 radians in the counterclockwise direction. Then modify the M-file in part (a) adding to each iteration (for all three loops) a rotation defined by the matrix Q Note that the triangle should NOT end up in its original location like it should for 5(a). You might need to change the axes to see where it "lands."Explanation / Answer
% 5 (a)
c1 = .1;
c2 = .1;
M1 = [1,0,c1; 0,1,c2; 0,0,1];
M2 = [1,0,-c1; 0,1,0; 0,0,1];
for i = 1:20
T = T./M2;
T = T./M2;
end
for i = 1:20
T = T./M1;
end
% 5 (b)
% Rotate vector M1 in homogeneous coordinates
theta = pi/40;
update_M1 = M1*[1;1i]*exp(-1i*theta*pi/180);
% We got original T in 5 (a), so Rotate it by theta
axis([-7,7,-7,7])
axis square
figure(gcf);
for i = 1:20
T = M1*T;
set(p,'xdata',T(1,:),'ydata',T(2:))
pause(0.1)
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.