3 2D Transformation

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 14

BIT 2107

Computer Graphics

Lesson3: 2D Transformations

Lucy W. Mburu, Ph.D


Coordinate Systems

 The use of coordinate systems is fundamental


to computer graphics
 Coordinate systems are used to describe the
locations of points in space

3.2
What is Transformation?
 Transformation means changing
some objects, primitives or graphics by
applying rules.
 There exist various types of transformations,
such as:
 translation,
 scaling up or down,
 rotation,
 shearing, etc.
 When a transformation occurs on a 2D
plane, it is called 2D transformation.
3.3
Translations
 This involves moving an object.
 We translate a point by adding to the x and y
coordinates, respectively, the amount the point should
be shifted in the x and y directions.
 We translate an object by translating each vertex in
the object.

P2 = P 1 + T
Ty

P1 = ( x1 ) T = ( tx )
Tx ( y1 ) ( ty )

P2 = (x1 + tx)
3.4
(y1 + ty)
Scaling
 Scaling is a transformation that changes the size of
an object. We scale an object by scaling the x and y
coordinates of each vertex in the object.
P’ = P . S

P = ( x1 ) S = (sx 0)
( y1 ) (0 sy)

P’ = (x1sx)
(y1sy)

3.5
Scaling - Example
 Consider a square (0,0) (2,0) (0,2) (2,2) that has been scaled by 2 in
the x direction and by 3 in the y direction. Find the new coordinates
 Parameters involved: sx, sy, (x,y), (x’,y’)
 x’ = x * sx
 y’ = y* sy

3.6
Rotation
 "Rotation" means turning around a center:
 The distance from the center to any point on the
shape stays the same.
 Every object involved in rotation must make
a circle around the center:

3.7
Rotation About the Origin
 To rotate a line or polygon, we must rotate each of its
vertices.
 To rotate point (x1,y1) to point (x2,y2)
we observe:

From the illustration we know that:

3.8
Rotation - Example
 It is easier to see change in triangles using rotation
(than e.g., square geometries)
 Consider a triangle with the points (0,0(1,0)(1,1)
rotated 90°in anticlockwise manner. What will be the
new coordinates?

NB: Sin 90° = 1, Cos 90° = 0

3.9
Shear
 A shear is a transformation that slants the shape of an
object. Also called Skewing.
 There are two shear transformations:
 X-Shear: preserves the Y coordinate and changes are
made to X coordinates causing the vertical lines to tilt right
or left .
 Y-Shear: preserves the X coordinates and changes the Y
coordinates which causes the horizontal lines to transform
into lines which slopes up or
 However; in both the cases only one coordinate changes
its coordinates and other preserves its values.

3.10
Shears

3.11
Reflections
 A reflection is the mirror image of original object.
 It is a rotation operation with 180.
 The reflection has the same size as the original Mirror Line
image
 The central line is called the Mirror line

 The following figures show reflections with respect to X and


Y axes, and about the origin respectively.

3.12
Reflections

Reflection about the y-axis Reflection about the x-


axis
-1 0 0 1 0 0
0 1 0 0 -1 0
0 0 1 0 0 1

3.13
More Reflections

Reflection about the origin Reflection about the line y =


x
-1 0 0 0 1 0
0 -1 0 1 0 0
0 0 1 0 0 1

3.14

You might also like