0% found this document useful (0 votes)
30 views

C1 Sec 3

This document discusses transformation matrices for 2D shapes. It explains how to use rotation, translation, scaling and reflection matrices to transform vertex matrices representing 2D objects. Examples are provided to demonstrate rotating, translating, scaling and reflecting triangles and other shapes.

Uploaded by

Nombulelo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

C1 Sec 3

This document discusses transformation matrices for 2D shapes. It explains how to use rotation, translation, scaling and reflection matrices to transform vertex matrices representing 2D objects. Examples are provided to demonstrate rotating, translating, scaling and reflecting triangles and other shapes.

Uploaded by

Nombulelo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

1.

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

vector with origin at the coordinate (x,y).

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')

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 1


Representing straight line shapes in 2 dimensions as a matrix

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

, the vertex matrix is

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

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 2


1.3.2 Rotation Matrix
The matrix used to rotate an object defined by the vertex matrix counter clockwise by radians is

where . Note that the product is always compatible but is

not.

Examples

i) Rotate the vector with tail at the origin and head at counter-clockwise through an angle radians

Step 1: Define with .

Step 2: The new coordinates of the head and tail are calculated as

where the tail is now at and the head is at

x=pi/2; R=[cos(x) -sin(x);sin(x) cos(x)]; A=[0 1;0 2];


Anew=R*A

Anew = 2×2
0 -2.0000
0 1.0000

quiver(0,0,1,2,0,'m') % m=magenta (purple)


hold on
quiver(0,0,-2,1,0,'k--')
hold off
legend({'A','A_{new}'})
title('Rotate')

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 3


ii) Rotate the closed object with coordinate points (1,1), (1,2), (3,4) and (3,3) radians counter-clockwise.

Step 1: and

Step 2: The new coordinates are at

The object is now defined by joining the coordinates .

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

and 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')

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 4


1.3.3 Translation matrix
To move a vertex matrix to a different location in the xy plane, you add a translation matrix of the same
dimensions as to . The new vertices are then defined by . Moving to the left by
units will require adding to all the components of and moving to the right will require adding .
Moving upwards units will require adding units to the components of and moving down adding
units.

Example

Move the triangle with coordinates/vertices (2,-1), (4,3) and (-3,2) five units to the left and two units upwards

Step 1: The vertex matrix is and

Step 2: The new coordinates are at

A=[2 4 -3 2;-1 3 2 -1]; T=[-5 -5 -5 -5;2 2 2 2];


Anew=A+T

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')

The new coordinates are (-3,1) (-1,5) and (-8,4)

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 5


1.3.4 Scaling matrix
To change the width of the object defined by the vertex matrix by a factor and the height by a factor ,
multiply with the scaling matrix

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.

Step 1: The vertex matrix is and

Step 2: The new coordinates of the stretched shape is

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')

The new coordinates are at (1,0), (2,0) and (1.5,4)


DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 6
ii) If you would rather indicate the changes made to in i) so that it appears as shown in the graph below, what
transformation would you apply to to obtain

Step 1: The graph of has been moved 1.5 units to the right. We must therefore add the translation matrix

to

Step 2:

1.3.5 Reflection matrix


Mirror images of the object defined by the vertex matrix can be made about the axes
by multiplying with one of the following reflection matrixes:

Reflect A about the axes : in the order

Reflect A about the axes : in the order

Reflect A about diagonal : in the order

Example

Reflect the object with vertices (2,4), (4,3), (4,0), (2,-1) and (0,2) about the y axes.

Step 1: and

Step 2: The new coordinates are at

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 7


A=[2 4 4 2 0 2;4 3 0 -1 2 4]; % for closed forms - repeat first coordinate at end
My=[-1 0;0 1];
Anew=My*A

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')

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 8


Paced Exercise (1C)

1.Calculate the rotation matrix responsible for rotating the triangle in the top to the one in the bottom

• The vertex matrix is and the rotated matrix is where

. You must calculate and use the definition of to calculate .


• Matrix multiplication is order sensitive so you will have to multiply in the same way on both sides. In this
case, from the right:

• 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.

• You should find that

• You should find that

• You should find that this corresponds to


• If you calculate the product , you will find that

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 9


A=[1 3;2 5]; %only use the first two coordinates
B=[-1 -3 ;-2 -5];
R=B*inv(A)

R = 2×2
-1 0
0 -1

R=[cos(pi) -sin(pi); sin(pi) cos(pi)];


A=[1 3 -3;2 5 4];
B=R*A

B = 2×3
-1.0000 -3.0000 3.0000
-2.0000 -5.0000 -4.0000

Yes this is the correct rotation

2. Calculate the translation matrix responsible for moving the bottom triangle to the top

• Here

• You must solve where or rather

• You should find that . was moved 5 units to the left and 2 units upwards

A=[-3 2 4;-2 -1 3];


T=[-5 -5 -5;2 2 2];
B=A+T

B = 2×3
-8 -3 -1
0 1 5

Yes this is the correct translation

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 10


3. Calculate the reflection matrix responsible for reflecting the right hand object to the left

• 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

(these correspond to points A and B transforming to points A' and


B')

• 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

position defined by . Calculate the matrix representing the transformation from .

• In order of the consecutive processes, which is represented as the

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 .

DR ERASMUS MEM11A, CMA11A, EMA115C CHAPTER 1 SECTION 3 11

You might also like