fprintf( ‘————————————-\n’ );
fprintf( ‘Q 1\n’ );
fprintf( ‘————————————-\n’ );
a = [ 0 0 1 ]’;
b = [ 1 0 1 ]’;
c = [ 0 1 1 ]’;
S_y2 = [ 1 0 0; 0 2 0; 0 0 1 ];
T_IfromABC = S_y2;
fprintf( ‘T_IfromABC (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (T_IfromABC)’ );
fprintf( ‘\n’)
% Scale y=2 followed by R(180) and Translate by x = 1 and y = 2
R_180 = [ cos(pi) -sin(pi) 0; sin(pi) cos(pi) 0; 0 0 1 ];
T_x1y2 = [ 1 0 1; 0 1 2; 0 0 1];
T_IIfromABC = T_x1y2 * R_180 * S_y2;
fprintf( ‘T_IIfromABC (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f\n’, (T_IIfromABC)’ );
fprintf( ‘\n’)
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 2\n’ );
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 2.1\n’ );
a = [ -5 4 6 1 ]’;
theta = 30/180*pi;
R_x30 = [ 1 0 0 0;
0 cos(theta) sin(theta) 0;
0 -sin(theta) cos(theta) 0;
0 0 0 1 ];
T_x1y3z_2 = [ 1 0 0 1;
0 1 0 3;
0 0 1 -2;
0 0 0 1 ];
T_trans = T_x1y3z_2 * R_x30;
fprintf( ‘T_object (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_trans)’ );
fprintf( ‘\n’)
a_trans = T_trans * a;
aCartesian = a_trans(1:3)/a_trans(4);
fprintf( ‘a_trans: \n’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T\n’, aCartesian );
fprintf( ‘\n’)
fprintf( ‘Q 2.2\n’ );
theta = 90/180*pi;
R_z90 = [ cos(theta) -sin(theta) 0 0;
sin(theta) cos(theta) 0 0;
0 0 1 0;
0 0 0 1 ];
T_x_2y_2z1 = [ 1 0 0 -2;
0 1 0 -2;
0 0 1 1;
0 0 0 1 ];
F_0in2 = R_z90 * T_x_2y_2z1;
R_transpose = F_0in2(1:3,1:3)’;
F_2from0 = [ R_transpose, -R_transpose*F_0in2(1:3,4);
0 0 0 1 ];
fprintf( ‘Inverse frame transform F_2from0 (homogenous): \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (F_2from0)’ );
fprintf( ‘\n’)
org_trans = F_2from0(1:3,4);
fprintf( ‘Origin with F_2from0: \n’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T\n’, org_trans );
fprintf( ‘\n\n’)
clear all;
fprintf( ‘————————————-\n’ );
fprintf( ‘Q 3\n’ );
fprintf( ‘————————————-\n’ );
% Using object transform
% Naming the blocks from lower left to upper right
% 4 5 6
% 3
% 1 2
% Pick the lower-left-front as origin of coordinate system. Orientation
% as shown for the cube x to the right, y up and z out of the paper
% scale in y by 2
T_0from1 = [ 1 0 0 0;
0 2 0 0;
0 0 1 0;
0 0 0 1 ];
fprintf( ‘Scale in y by 2 (homogenous) T_0from1 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from1)’ );
fprintf( ‘\n’)
% scale in y by 2 and translate 2 over
T_0from2 = [ 1 0 0 2;
0 2 0 0;
0 0 1 0;
0 0 0 1 ];
fprintf( ‘Scale in y by 2 and translate 2 over (homogenous) T_0from2 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from2)’ );
fprintf( ‘\n’)
% Scale in x by 3 and translate 2 up
T_0from3 = [ 3 0 0 0;
0 1 0 2;
0 0 1 0;
0 0 0 1 ];
fprintf( ‘Scale in x by 3 and translate 2 up (homogenous) T_0from3 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from3)’ );
fprintf( ‘\n’)
% Scale in y by 1.5 and translate 4.5 up, 0.5 right and 0.5 in
T_0from4 = [ 1 0 0 0.5;
0 1.5 0 4.5;
0 0 1 -0.5;
0 0 0 1 ];
fprintf( ‘Scale in y by 1.5 and translate 4.5 up and 0.5 right and in\n’ )
fprintf( ‘T_0from4 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from4)’ );
fprintf( ‘\n’)
% Scale in y by 2 move 1 right and 3 up
T_0from5 = [ 1 0 0 1;
0 2 0 3;
0 0 1 0;
0 0 0 1 ];
fprintf( ‘Scale in y by 2 and translate 1 right and 3 up\n’ )
fprintf( ‘T_0from5 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from5)’ );
fprintf( ‘\n’)
% Scale in y by 1.5 and translate 4.5 up, 2.5 right and 0.5 in
T_0from6 = [ 1 0 0 2.5;
0 1.5 0 4.5;
0 0 1 -0.5;
0 0 0 1 ];
fprintf( ‘Scale in y by 1.5 and translate 4.5 up, 2.5 right and 0.5 in\n’ )
fprintf( ‘T_0from6 = \n’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f\n’, (T_0from6)’ );
fprintf( ‘\n’)