Download as pdf or txt
Download as pdf or txt
You are on page 1of 24

TRANSFORMATIONS.

A. TWO DIMENSIONAL TRANSFORMATIONS.

- Transformations are fundamental part of computer graphics.


- In order to manipulate object in 2D spare we must apply various transformation
functions to the object .
- This allows us to change the position, size and orientation of objects .
- There are five fundamental 2D transformation functions:
 Translation (Move)
 Scaling
 Rotation
 Mirror reflection
 Shearing

1. Translation
This allows you to move an object in the x-y plane. This is accomplished by
adding a translation distance to the x and y coordinates of the original vertex.

B B1

A<------------------------------------------------->A1 (x1, y1)

(x , y)

X1=x+Tx

Y1=y+Ty

Where (Tx , Ty) is called translation vector

1
In matrix notation

The equation can be written in matrix form as:

X1 x Tx x+Tx

Y1 = y + Ty = y + Ty

Alternatively

x1 1 0 Tx x

y1 = 0 1 Ty y

1 0 0 1 1

2
For 3D translation

X1 1 0 0 Tx x

Y1 = 0 1 0 Ty y

Z1 0 0 1 Tz z

1 0 0 0 1 1

3
2. SCALING
The scale function allows us to change the size of an object. Each of the vertex’s original
coordinates are multiplied by a scaling factor.

X1 = x.Sx

Y1 = y.Sy

Where Sx and Sy are scaling constant

A scaling constant greater than one indicates an expansion of length , and less than one,
compression of length.

After scaling transformation is performed the new object is located at different position relative
to the origin.

Matrix notation

X1 = Sx 0 x

Y1 0 Sy y

For Sx = 2, Sy =2

2 Sx =2

Y2 1 Sy= 1/2

1 3 x 1 2 4

4
Using 3X3 matrix, 2D scaling matrix is:

x1 Sx 0 0 x

y1 =
0 Sy 0 y

1 0 0 1 1

The following is the Matrix for 3D Scaling

x1 Sx 0 0 0 x

y1 =
0 Sy 0 0 y

z1 0 0 Sz 0 z

1 0 0 0 1 1

3. Rotation About the origin


In this transformation, the point or graphical entity is rotated about the point. In order to execute
the rotation, it is the necessary to know three inputs:

(i) the angle of rotation;

(ii) the point about which rotation is effected

(iii) direction of rotation

5
Consider a point (x,y) rotated about origin as shown below;

fig illustrating rotation process of a point P(x,y)

where is the angle of rotation , r is the radial vector , is the angle made by the radii vector
with +ve x axis.

It can be written as

x= rcos

y=rsin

Similarly, x1 = r cos ( + )

y1 = r sin ( + )

Expanding

x1 = r cos cos - r sin sin

= x cos - y sin

Similarly

y1= rsin cos + r cos sin

= xsin + ycos

6
Therefore, the general representation of equations of rotation

X1 = xcos 𝜃 - ysin 𝜃 --------- (1)

y1 = xcos 𝜃 + ysin 𝜃 ---------(2)

If direction of rotation is clockwise then is replaced by - in equal (1) and (2)

If rotation is effected or carried out about any point (XR, YR) then the equation of rotation can be
proved as

X1 = XR +(X-XR) cos 𝜃 -( y-YR)sin 𝜃

y1 = YR + (X-XR) sin 𝜃 +(Y-YR) cos 𝜃

Matrix of Rotation 2D (anticlockwise)

X1

= cos - sin x

Y1 sin cos y

Or using 3X 3 Matrix :

X1 cos -sin 0 x

Y1 = sin cos 0 y

1 0 0 1 1

7
In 3D (anticlockwise)

X1 cos -sin 0 0 x

Y1 Sin cos 0 0 y

Z1 0 0 0 z

1 0 0 0 1 1

NB: In clockwise rotation is replaced by –

Or using 3X 3 Matrix :

X1 cos sin 0 x

Y1 = -sin cos 0 y

1 0 0 1 1

8
4. REFLECTION
By using this routine, it is possible to obtain mirror image of an object.

Reflection is always carried out about an axis called the axis of reflection.

If the axis of reflection is the x-axis then the x- coordinates of the point remains unchanged while
the y-coordinate flips (changes sign).

Similarly when the axis of reflection is the y-axis the y-coordinate of the reflection remains the
same while the x coordinate changes its sign.

Reflection About x-axis

y P(x,y)

x-axis

P1(x1,-y1)

Fig Reflection about x-axis

Reflection Matrix

X1 x 1 0 x

Y1 = -y = 0 -1 y

Ie Mx = 1 0

0 -1

9
Using a 3X 3 Matrix

Mx = 1 0 0

0 -1 0

0 0 1

That is:

x1 1 0 0 x

y1 = 0 -1 0 y

1 0 0 1 1

Reflection about y-axis

(-x,y)p1 (x,y).p

Reflection matrix

x1 = x -1 0 = -x

y1 y 0 1 y

10
Or using 3X3 Matrix:

x1 = -1 0 0 x

y1 0 1 0 y

1 0 0 1 1

Reflection matrix when the axis of reflection is the line passing through the
origin
y

y=mx

The equation of the line passing through origin is y = mx; where m is the slope
(m=tan )

11
The following steps should be taken:

1. Rotate the line that is the axis of reflection y=mx in clock wise direction by angle
=tan-1 (m) to align it with x-axis. Rotation matrix is given by

[A1] =

Cos(- -sin(- ) 0

sin(- ) cos( ) 0

0 0 1

Cos( sin( ) 0

= -sin( ) cos( ) 0

0 0 1

2. Reflection about x-axis obtained let [A2] represent the reflection matrix then.

[A2 = 1 0 0

0 -1 0

0 0 1

12
3. Now the line is rotated by angle in counter-clockwise direction so that original
position of line is restored

[A3] = cos sin 0

-sin cos 0

0 0 1

The resultant matrix [R] is obtained by concatenating [A1], [A2] [A3] as

[R] = [A3]x[A2]x[A1]

13
Reflection matrix when Axis of Reflection is a line y= mx+c
(equation of a line not passing through origin)

The following steps are involved:

1. Translate the line so that it passes through origin.

2. Rotate so as to align it with one of the axis

3. Next, Reflection about the axis is obtained

4. The line is rotated back to u-s original inclination

5. The line is translated back to its original position

The resultant matrix is obtained by concatenating the above five transformation matrices.

14
5. Shearing
A shearing Transformation produces distortion of an object or an image. There are
two types of shears, refer figs.

1) X-direction shear

2) Y-direction shear

In x-direction sheer, the x-coordinate will change while the y-coordinate will
remain same

y y

x- direction shear y-direction sheer x

if shx is the shearing factor in x director then the basic equation are

x1 = x +shx y

y1 =y

In the y-direction shear, the y-coordinate will change while the x-coordinate will
remain the same. If shy is the shearing factor in the y-direction then basic equations
are:

x1 = x

y1 = y +x . xshy

15
Shear matrices

For x-direction shear

x1 1 shx x

y1 = 0 1 y

For y-direction shear

x1 = 1 0 x

y1 shy 1 y

Shearing in both x and y is given by :

x1 = 1 shx x

y1 shy 1 y

The 3X3 Shearing matrix in 2D is:

x1 1 shx 0 x

y1 = shy 1 0 y

1 0 0 1 1

16
Worked Examples

1. A triangle is defined in two dimensions by its vertices (1,2), (1,3) and (2,2) .
Perform the following transformations on this triangle

a) Translate the triangle in scale by 2 units in x-direction and 3-units in the y-


direction

b) Scale the original triangle by a factor of 1.5

c) Rotate the original triangle by 450 about origin in clockwise direction

d) Show the sequence of transformation on graph paper

Solutions
a) The general transformation matrix for translation is given as

1 0 Tx

0 1 Ty

0 0 1

Where (Tx , Ty) represent translation vector

In the problem Tx =2; Ty =3

Transition matrix [A] = 1 0 2

0 1 3

0 0 1

17
The transferred Image of the vertices of the triangle can be found out as

1 0 2 1 1 2 = 3 3 4

0 1 3 2 3 2 5 6 5

0j 0 1 1 1 1 1 1 1

The transferred Image of the vertices of the triangle is given as

(1, 2) (3,5)

(1, 3) (3,6)

(2,2) (4,5)

b) The generalized transformation matrix for scaling is

Sx 0 0

0 Sy 0

0 0 1

Where (Sx , Sy ) are the scaling factor in x and y direction respectively.

In the problem Sx = Sy = 1.5

Scaling matrix is 1.5 0 0

0 1.5 0

0 0 1

18
The transferred Image of vertices of triangle and scaling can be found out as:

1.5 0 0 1 1 2 1.5 1.5 3

0 1.5 0 2 3 2 = 3 4.5 3

0 0 1 1 1 1 1 1 1

The transformed Image of the vertices of triangle are

(1, 2) (1.5, 3)

(1, 3) (1.5, 4.5)

(2, 2) (3, 3)

c) Generalised transformation matrix for rotation about origin is given as

cos sin 0

-sin cos 0

0 0 1

With as angle of rotation

In the …………. Problem = 450

19
The T.M for rotation can be written as

0.707 0.707 0

-0.707 0.707 0

0 0 1

The transformed Image of the vertices triangle can be found out as

0.707 0.707 0 1 1 2

-0.707 0.707 0 2 3 2

0 0 1 1 1 1

2.121 2.828 2.828

= 0.707 1.414 0

1 1 1

The transformed Image of the vertices of triangle are

(1, 2) (2.121, 0.707)

(1, 3) (2.83, 1.414)

(2, 2) ( 2.83 , 0 )

20
Find the reflection of the point (3,11) about a line y=3x+4

Solution

The transformation matrix for reflection about a line y=3x+4 can be obtained by using a
concatenation process as follows

x=3x+4

=tan-1 (3)=71.560

(0,4)

The line (y=3x+4) is translated by 4 units in negative y-direction so that it posse through the
origin

Let [A] represent the translation matrix and is given by:

[A]= 1 0 0

0 1 -4

0 0 1

The line (y=3x+4)is then rotated in clockwise direction by an angle 71 so that it coincides with
x-axis.

21
Let [B]represent the T.M. for this rotation.

[B]= Cos (-71.56) - sin(-71.56) 0

-sin(-71.56) cos(-71.56) 0

0 0 1

- Getting the reflection above the line, which coincides with x-axis

- Let [C] represent the T.M for this reflection

[C] =

1 0 0

0 -1 0

0 0 1

Rotating the line by an angle 71.560 Anti -Clockwise direction, let [D] represent
the T.M for this rotation

[D] = cos (71.56) - sin(71.56) 0

sin(71.56) cos(71.56) 0

0 0 1

22
= 0.316 - 0.948 0

0.948 0.316 0

0 0 1

Translating the line by 4 units in position y-direction, so that original position line is
restored

Let [E] represent the T.M for translation

[E]= 1 0 0

0 1 4

0 0 1

The T.M can be obtained by concatenating [A], [B], [C], [D],[E]

[R]= [E] [D] [C] [B] [A]

[R] =

23
Vertex = 3

11 =

The transferred Image of point (3,11)can be written as

(3,11) [?, ? ]

24

You might also like