fprintf( ‘————————————-\n’ );
fprintf( ‘Q 1\n’ );
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 1.1\n’ );
M_scale = [ 3 0; 0 2 ];
fprintf( ‘Scaling: \n’)
% Transpose just to fix matlab printing
fprintf( ‘%5.2f %5.2f\n’, M_scale’ );
fprintf( ‘\n\n’)
fprintf( ‘Q 1.2\n’ );
H_x = [ 1 2; 0 1 ];
fprintf( ‘Shear x: \n’)
fprintf( ‘%5.2f %5.2f\n’, H_x’ );
H_y = [ 1 0; 2 1 ];
fprintf( ‘Shear y: \n’)
fprintf( ‘%5.2f %5.2f\n’, H_y’ );
fprintf( ‘\n\n’)
fprintf( ‘Shear x/y (symmetric but non-unit diagonal): \n’)
fprintf( ‘%5.2f %5.2f\n’, (H_y*H_x)’ );
fprintf( ‘\n\n’)
fprintf( ‘Q 1.3\n’ );
delta = -90/180*pi;
R_90 = [ cos(delta) -sin(delta); sin(delta) cos(delta) ];
fprintf( ‘Rotation -90: \n’)
fprintf( ‘%5.2f %5.2f\n’, R_90′ );
fprintf( ‘\n\n’)
clear all;
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 2\n’ );
fprintf( ‘————————————-\n’ );
M_trans = [ 1 0 -1; 0 1 2; 0 0 1 ];
M_scale = [ 3 0 0; 0 2 0; 0 0 1 ];
fprintf( ‘Scaling then translation (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (M_trans * M_scale)’ );
fprintf( ‘\n\n’)
H_x = [ 1 2 0; 0 1 0; 0 0 1];
fprintf( ‘Shear x then translation (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (M_trans*H_x)’ );
H_y = [ 1 0 0; 2 1 0; 0 0 1 ];
fprintf( ‘Shear y then translation (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (M_trans*H_y)’ );
fprintf( ‘\n\n’)
fprintf( ‘Shear x/y then translation (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (M_trans*H_y*H_x)’ );
fprintf( ‘\n\n’)
delta = -90/180*pi;
R_90 = [ cos(delta) -sin(delta) 0; sin(delta) cos(delta) 0; 0 0 1];
fprintf( ‘Rotation -90 then translation (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (M_trans*R_90)’ );
fprintf( ‘\n\n’)
clear all;
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 3\n’ );
fprintf( ‘————————————-\n’ );
M = [ sqrt(2) 3*sqrt(2);
-sqrt(2) 3*sqrt(2) ];
[U,S,V] = svd(M);
fprintf( ‘U: \n’)
fprintf( ‘%5.2f %5.2f\n’, U’ );
fprintf( ‘\n’)
fprintf( ‘S: \n’)
fprintf( ‘%5.2f %5.2f\n’, S );
fprintf( ‘\n’)
fprintf( ‘V^T: \n’)
fprintf( ‘%5.2f %5.2f\n’, V );
fprintf( ‘\n’)
fprintf( ‘Verify that M=USV^T: \n’)
fprintf( ‘%5.2f %5.2f\n’, (U*S*transpose(V) – M)’ );
fprintf( ‘————————————-\n’ );
fprintf( ‘\n’)
A = M*transpose(M);
fprintf( ‘A (symmetric matrix): \n’)
fprintf( ‘%5.2f %5.2f\n’, A*A’);
fprintf( ‘\n’)
[R,D] = eig( A );
fprintf( ‘R (eigendecomposition): \n’)
fprintf( ‘%5.2f %5.2f\n’, R’);
fprintf( ‘D (eigendecomposition): \n’)
fprintf( ‘%5.2f %5.2f\n’, D’);
fprintf( ‘Verify that A=RDR^T: \n’)
fprintf( ‘%5.2f %5.2f\n’, (R*D*transpose(R) – A)’ );
fprintf( ‘\n\n’)
clear all;
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 4\n’ );
fprintf( ‘————————————-\n’ );
p = [ 2 -1 -5 1 ]’;
t0 = [ sqrt(2)/2 -sqrt(2)/2 0 0 ]’;
t1 = [ 0 0 -1 0 ]’;
n = [ sqrt(2)/2 sqrt(2)/2 0 0 ]’;
Sx2 = [ 2 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1 ];
Rx90 = [ 1 0 0 0; 0 0 -1 0; 0 1 0 0; 0 0 0 1];
Ty1 = [ 1 0 0 0; 0 1 0 1; 0 0 1 0; 0 0 0 1];
Tall = Ty1 * Rx90 * Sx2;
pH = Tall * p;
pCartesian = pH(1:3)/pH(1); % not necessary here
fprintf( ‘Transformed p \n’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T\n’, pCartesian );
fprintf( ‘\n’)
nH = transpose(inv(Tall))*n;
nCartesian = nH(1:3); % direction – do not divide by 0!
fprintf( ‘Transformed n \n’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T\n’, nCartesian );
fprintf( ‘\n’)
fprintf( ‘Verify normal is normal to tangent plane. Before: %5.2f %5.2f\n’, …
dot(n,t0),dot(n,t1));
fprintf( ‘\n’)
fprintf( [‘Verify normal is still normal to the transformed tangent plane: ‘ …
‘%5.2f %5.2f\n’], dot(transpose(inv(Tall))*n, Tall * t0), …
dot(transpose(inv(Tall))*n, Tall * t1))
fprintf( ‘\n’)
clear all;