Sei sulla pagina 1di 29

COMPUTER GRAPHICS

2D GEOMETRICAL TRANSFORMATIONS
Institute of Information and Communication Technology
University of Sindh, Jamshoro

Dr. Zeeshan Bhatti


BSIT-PIV
Chapter 4
Foley & Van Dam, Chapter 5
BY: DR. ZEESHAN BHATTI

2D GEOMETRICAL
TRANSFORMATIONS
Translation
Scaling

Rotation
Shear
Matrix notation

Compositions
Homogeneous coordinates

2D GEOMETRICAL
TRANSFORMATIONS
Assumption: Objects consist of points and lines.
A point is represented by its Cartesian coordinates:
P = (x, y)
Geometrical Transformation:
Let (A, B) be a straight line segment between the points A and B.
Let T be a general 2D transformation.
T transforms (A, B) into another straight line segment

(A, B), where:


A=TA and
B=TB

TRANSLATION

SCALE

SCALE
How can we scale an object without moving its origin (lower left
corner)?

REFLECTION
Special case of scale

ROTATION
Rotate(): (x, y) (x cos()+y sin(), -x sin()+y cos())

ROTATION
How can we rotate an object without moving its origin (lower left
corner)?

SHEAR
Shear (a, b): (x, y) (x+ay, y+bx)

CLASSES OF TRANSFORMATIONS
Rigid transformation (distance preserving):
Translation + Rotation
Similarity transformation (angle preserving):
Translation + Rotation + Uniform Scale
Affine transformation (parallelism preserving):
Translation + Rotation + Scale + Shear

All above transformations


are groups where
Rigid Similarity Affine

MATRIX NOTATION

2D TRANSFORMATIONS
2D object is represented by points and lines that join
them

Transformations can be applied only to the the points


defining the lines
A point (x, y) is represented by a 2x1 column vector, so
we can represent 2D transformations by using 2x2
matrices:

TRANSLATION
To translate a point with coordinate (x1, y1) to a new location using
displacements (dx, dy), following equations can be used:
x2 = x1 +dx

and

y2 = y1+dy
Here (x2, y2) is the new coordinate of the point. The above equation
can be represented in matrix notation as:
2
1

=
+
2
1

This matric notation can be put as a vector addiction:


V2 = T +V1

Where
1
v1 =
1

2
V2 =
2

PROBLEM: CONSIDER A POLYGON WITH FOLLOWING


VERTEX. TRANSLATE IT IN (5, 7)
V1= (5,6), V2=(10, 6), V3=(7, 12) V4=(14, 15)

SCALE
The size of an object can be changed by the scaling transformation.
Objects can be scaled either the X or Y direction, or both of them
simultaneously, scaling by scale factors sx and sy along the X and Y
directions can be expressed mathematically as
x2 = sxx1

and

y2 = syy1
Here (x2, y2) is the new coordinate of the point. The above equation can
be represented in matrix notation as:
2
1

=
x
2
1

This matric notation can be put as a vector addiction:


V2 = T x V1
Where
1
v1 =
1

2
V2 =
2

Reflection

<
0
>
Decrease Size
(No Object/Size 0)

<

1
>
Increase Size
(Same Size)

Scale
Scale (a, b):
a
0

(x, y) (ax, by)


0 x
ax

by
b y

If a or b are negative, we get reflection

Inverse: S-1(a,b) = S(1/a, 1/b)

ROTATION
Rotation can be performed in an
anticlockwise or a clockwise direction.
The axis of rotation may be X-axis or Y-axis
or any arbitrary line on the X-Y plane.
Rotations are performed about some fixed
point called pivot point or centre of rotation
or anchor point.
Rotations are measured by angular
displacements, we measure coordinate value
in term of the radius of rotation and angle
of rotation, i.e. polar coordinates.

Rotation
Rotate(
(x, y) (x cos()+y sin(), -x sin()+y cos())
cos
sin

sin x x cos y sin


cos y x sin y cos

Inverse: R-1(q) = RT(q) = R(-q)

Shear
Shear (a, b): (x, y) (x+ay, y+bx)
1
b

a x
x ay

1 y
y
bx

Reflection
Reflection through the y axis:
1
0

0
1

Reflection through the x axis:


1
0

0
1

Reflection through y = x:
0
1

1
0

Reflection through y = -x:


0
1

1
0

Composition of Transformations
A sequence of transformations can be
collapsed into a single matrix:
x
x
A B C D
y
y

Note: Order of transformations is important!


translate

rotate

rotate

translate

Translation
Translation (a, b):
x
y

x a
y b

Problem: Cannot represent translation


using 2x2 matrices
Solution:
Homogeneous Coordinates

Homogeneous Coordinates
Is a mapping from Rn to Rn+1:
( x , y ) ( X , Y , W ) ( tx , ty , t )

Note: All triples (tx, ty, t) correspond to the


same non-homogeneous point (x, y)
Example (2, 3, 1) (6, 9, 3).
Inverse mapping:

( X ,Y ,W )

Y
,
W

TRANSLATION

SHEAR

THANKYOU

Q&A
Referred Book
Computer Graphics: Principles and Practice in C,
by J. D. Foley, A. Van Dam, S. K. Feiner, J. F. Hughes.
Hardcover, 1200 pages, Addison-Wesley Pub Co; 2nd edition,
For Course Slides and Handouts
web page:

https://sites.google.com/site/drzeeshanacademy/
Blog:

http://zeeshanacademy.blogspot.com/
Facebook:

https://www.facebook.com/drzeeshanacademy

BY: DR. ZEESHAN BHATTI

29

Potrebbero piacerti anche