Question: Example 9 In this example we first translate the square horizontally 1 2 units using increments of 0 . 4 . We then rotate the

Example 9
In this example we first translate the square horizontally 12 units using increments of 0.4. We then
rotate the resulting square clockwise pi//2 radians around the vertex (13,0) using increments of pi//10
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/10; % 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,13;0,1,0;0,0,1]Q'[1,0,-13;0,1,0;0,0,1]; % rotation matrix about (13,0)
p = plot(S(1,:),S(2,:)); % plot the original square
axis equal, axis([-0.5,15,-2,5]), grid on
for i =1:30
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:5
S=QP*S; % compute the rotated square
set(p,'xdata',S(1,:),'ydata',S(2,:)); % plot the rotated square
pause (0.1)
end
EXERCISES
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 12 units using 30 iterations, and
then rotating it counterclockwise pi//2 radians around the point (1,0) using 5 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

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 Programming Questions!