C1 Sec 3
C1 Sec 3
3 Transformation matrixes in 2D
1.3.1 The quiver command
Graphically representing vectors in Matlab requires the quiver command. quiver(x,y,p-x,q-y,s, 'colour') will
draw an arrow with tail at the coordinate (x,y) and the head at (p,q) where s and colour are interpreted as
follows
• s: s=0 will give you the actual arrow between the two coordinates. s=2 will give you an arrow of twice
the original arrow's length etc. If you use the reduced command quiver(x,y,p-x,q-y,'colour') , Matlab
will decide what s should be.
• colour: Choose the colour of the arrow as either 'k'=black, 'm'=magenta (purple), 'g'=green, 'r'=red. If
you use the reduced command quiver(x,y,p-x,q-y), Matlab will decide which colour to use and what s
should be.
The length u=p-x is the horizontal component of the vector joining (x,y) and (p,q) and the length v=q-y is the
vertical component. Therefore, the command quiver(x,y,u,v,s,'colour') will draw an arrow corresponding to the
In Extending the two dimensional case to three dimensions, the command quiver3(x,y,z,p-x,q-y,r-z,s, 'colour')
will draw an arrow with tail at the coordinate (x,y,z) and the head at (p,q,r) . For example, drawing the vector
with tail at the origin (0,0,0) and head at (1,1,1) as well as the vector with tail at (1,0,1) and head at (-2,1,2) is
coded as follows:
a=quiver3(0,0,0,1-0,1-0,1-0,0);
hold on
b=quiver3(1,0,1,-2-1,1-0,2-1,0,'--');
hold off
legend({'a','b'})
title('Vectors in 3 dimensions')
Two dimensional shapes formed by joining straight lines can be expressed in terms of a vertex matrix containing
the coordinates of the starting and ending coordinate as well as all the joint coordinates in between. These
shapes can be moved around or scaled in the two dimensional space by either multiplying or adding special
matrixes to the vertex matrix. For example, if a shape is defined by the coordinates
For a closed shape, the first and last entry in is the same coordinate, for example, given the closed object
defined by the vertex matrix is
not.
Examples
i) Rotate the vector with tail at the origin and head at counter-clockwise through an angle radians
Step 2: The new coordinates of the head and tail are calculated as
Anew = 2×2
0 -2.0000
0 1.0000
Step 1: and
Note in graphically representing a closed object we rather use the closed form where the
start and end coordinate is the same. In referring to all the coordinates of , you use the command
x=pi;
R=[cos(x) -sin(x);sin(x) cos(x)];
A=[1 1 3 3 1;1 2 4 3 1]; % first coordinate is repeated at the end
Anew=R*A
Anew = 2×5
-1.0000 -1.0000 -3.0000 -3.0000 -1.0000
-1.0000 -2.0000 -4.0000 -3.0000 -1.0000
plot(A(1,1:5),A(2,1:5),'g') % plot x vs y A
hold on
plot(Anew(1,1:5),Anew(2,1:5),'--')% plot x vs y of Anew
hold off
legend({'A','A_{new}'})
title('Rotate')
Example
Move the triangle with coordinates/vertices (2,-1), (4,3) and (-3,2) five units to the left and two units upwards
Anew = 2×4
-3 -1 -8 -3
1 5 4 1
plot(A(1,1:4),A(2,1:4),'g')
hold on
plot(Anew(1,1:4),Anew(2,1:4),'--')
hold off
legend({'A','A_{new}'})
title('Translation')
in the order
Example
i) Stretch the triangle with vertices (2,0) , (4,0) and (3,2) by a factor 2 in height and a factor 1/2 in width.
A=[2 4 3 2;0 0 2 0]; % for closed forms, repeat first coordinate at the end
S=[1/2 0;0 2]; Anew=S*A
Anew = 2×4
1.0000 2.0000 1.5000 1.0000
0 0 4.0000 0
plot(A(1,1:4),A(2,1:4),'g')
hold on
plot(Anew(1,1:4),Anew(2,1:4),'--')
hold off
legend({'A','A_{new}'}); title('Scale')
Step 1: The graph of has been moved 1.5 units to the right. We must therefore add the translation matrix
to
Step 2:
Example
Reflect the object with vertices (2,4), (4,3), (4,0), (2,-1) and (0,2) about the y axes.
Step 1: and
Anew = 2×6
-2 -4 -4 -2 0 -2
4 3 0 -1 2 4
plot(A(1,1:6),A(2,1:6),'m')
hold on
plot(Anew(1,1:6),Anew(2,1:6),'--')
hold off
legend({'A','A_{new}'})
title('Reflection')
1.Calculate the rotation matrix responsible for rotating the triangle in the top to the one in the bottom
• As is not square, its inverse can't be determined. You will have to create a version of that is
square. This you do by just tracing the first two vertices (these
correspond to transforming X and Y to X' and Y'). The reasoning behind this is that rotates all
coordinates in the same way, whatever happened to the first two coordinates will also happen to a third,
fourth etc.
R = 2×2
-1 0
0 -1
B = 2×3
-1.0000 -3.0000 3.0000
-2.0000 -5.0000 -4.0000
2. Calculate the translation matrix responsible for moving the bottom triangle to the top
• Here
• You should find that . was moved 5 units to the left and 2 units upwards
B = 2×3
-8 -3 -1
0 1 5
• Here
• You must solve where . This will require multiplying the equation from the right with .
Reduce to 2x2 versions by only using the first two transformed coordinate pairs
• You should find that the reflection was about the axes as
4. An object defined by the vertex matrix is rotated, then scaled and then reflected with final
matrix . Let be the product of all the processes in the order described, then
and . You must calculate .
• You should find that . You will require more information about each individual process to
be able to determine the expressions for .