Matlab: Matrices as 2D transformations (mappings)

x-axis scaling

>> Dx = [ 2 0; 0 1]

y-axis scaling

>> Dy = [ 1 0; 0 3]

scaling in both axes

>> Dxy = Dx * Dy; % composition of the transformations

mirroring with respect to the y-axis

>> Zy = [ -1 0; 0 1]

90 degree rotation

>> R90 = [ 0 -1; 1 0]

alpha rotation

alpha = - pi/6; % radians
Ralpha = [ cos(alpha) -sin(alpha); sin(alpha) cos(alpha)]

shear

>> SH = [ 1 1; 0 1]

symmetric transformation

>> S = [ 3 -1; -1 2]

some general transformation

>> A = [1 2; 3 -1.5]

Graphical representation of 2D transformations:

picture of a house

>> X=[ 0 6 6 5 5 4 4 3 0 0;
       0 0 5 6 8 8 7 8 5 0]; 
>> plot(X(1,:),X(2,:),'linewidth',2); axis equal; hold on;

transformation of the picture using matrix A

>> A = [ 1 1; 0 1];  % shear
>> B = A*X;  
>> plot(B(1,:),B(2,:),'r','linewidth',2)