Consider the matrix T representing the triangle in the previ

Consider the matrix T representing the triangle in the previous problems. In homogeneous coordinates

the matrix becomes

T=[-0.5,0,0.5,-0.5;-1,1,-1,-1;1,1,1,1];

In the following M-file we translate the triangle using c1 = :1 and c2 = :1 for 20 times. We then translate

the triangle horizontally using c1 = 0.1 and c2 = 0 and 40 iterations.

clf

T=[-0.5,0,0.5,-0.5;-1,1,-1,-1;1,1,1,1]; % define the triangle in homogeneous coordinates

c1 =.1; c2 = .1;

M1 = [1,0,c1;0,1,c2;0,0,1]; % 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 the translated triangle

pause(0.1)

end

for i = 1:40

T=M2*T; % compute the translated triangle

set(p,\'xdata\',T(1,:),\'ydata\',T(2,:)); % plot the translated triangle

pause(0.1)

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.

Solution

Consider the matrix T representing the triangle in the previous problems. In homogeneous coordinates the matrix becomes T=[-0.5,0,0.5,-0.5;-1,1,-1,-1;1,1,1,1];

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site