Beruflich Dokumente
Kultur Dokumente
Computer Graphics
2-D Transformations
Outline
2-D Transformations
Transformation principles
Homogeneous coordinate systems
Concatenations
Matrix representations of transformations.
Transformations
The term transform means to change. This change can either be of shape, size
or position of the object. To perform transformation on any object, object
matrix X is changed by the transformation matrix T.
[X*]=[X] [T]
[X*] is matrix of transformed object.
[X] is a matrix of original object
[T] is transformation matrix.
The various transformations possible on an object are:
Translation
Rotation Basic Transformations
Scaling
Reflection
Shearing Other Transformations
Transformations
Elementary Transformations
1: Translation
2: Scaling
3: Rotation
4: Shearing
Translation
Translate by t
Scaling
A scaling changes the size of an object with two scale factors, Sx and Sy (if
Sx != Sy, then we have a non-uniform scale)
Qx Px S x
Q P S
y y y
Sx, Sy
Scale by
Sx, Sy
Original points Transformed points
Rotation
Rotate by
Rotation - derivation
QX Rcos( ) [1]
Q y Rsin( ) [2]
PX R cos ( ) [3]
Py R sin ( ) [4]
Q
cos ( ) cos () cos () sin () sin ()
2D Reflections
y y y
x x
1 0 0 1 0 0 1 0 0
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
yx y x
0 1 0 0 1 0
1 0 0 1 0 0
0 0 1 0 0 1
Other transformations
Reflection:
x-axis y-axis
1 0 0
0 1 0
0 0 1
1 0 0
0 1 0
0 0 1
Other transformations
Reflection:
origin line x=y
1 0 0 0 1 0
0 1 0 1 0 0
0 0 1
0 0 1
Shearing
A shearing affects an object in a particular direction (in 2D, its either in the
x or in the y direction),results only in distortion of shape.
A shear in the x direction would be as follows:
Qx Px hPy
Q P
y y
The quantity h specifies what fraction of the y-coordinate should be added to
the x-coordinate, and may be positive or negative
More generally: a simultaneous shear in both the x and y directions would be
Qx Px hPy
Q P gP
y y x
Shearing
g =0, h=0.5
Shear by {g,h}
g=0.5, h=0.5
Shear by {g,h}
Other transformations
Shear:
x-direction y-direction
1 shx 0 1 0 0
0 1 0 sh 1 0
y
0 0 1 0 0 1
Matrix Representation
Qx a b Px t x
Q P t
y c d y y
i.e.
Q MP t
Transformations Summary
1: Translation T
Qx 1 0 Px t x
Q P t
y 0 1 y y
T
2: Scaling
Qx S x 0 Px 0
Q 0
S y Py 0
y
3: Rotation T
Qx cos sin Px 0
Q P 0
y sin cos y
4: Shearing T
Qx 1 h Px 0
Q P 0
y g 1 y
Problem
An affine transformation is composed of a linear combination followed by a
translation
Unfortunately, the translation portion is not a matrix multiplication but must
instead be added as an extra term, or vector this is inconvenient
P = M1P + M2
where M1 takes care of rotation and scaling,
while M2 takes care of translation.
This is undesirable!
1 0 0 1 1
S x 0 0 1 h 0
Scale by Sx, Sy
M 0 Sy 0
Shear by g, h: M g 1 0
0 0 1 0 0 1
Homogeneous Coordinates
Advantages
1. 2D transformations can be represented as 3x 3 matrices so that usage of the
operations become relatively easy.
2. It is a technique based on projective geometry.
3. Floating point arithmetic can be avoided by transforming them into integer
arithmetic.
1 1
e.g. ( , ) in 2D can be represented as (3,2,6) in homogeneous coordinates.
2 3
Multiple Transformations
The simple versions of rotation and scaling have been based around the
origin.
This means that when we rotate or scale, the object will also move, with
respect to the origin
Pivotal points
Often we wish to rotate or scale with respect to some pivotal point, not the
origin
Most significantly, we often wish to rotate or scale an object about its
centre, or midpoint
In this way, the objects location does not change
To do this, we relate the rotation or scaling about the pivotal point V, to an
elementary rotation or scaling about the origin
We first translate all points so that V coincides with the origin
We then rotate or about the origin
then all points are translated back, so that V is restored to its original
location
{x1,y1}
{0,0}
1 0 x1 cos sin 0 1 0 x1
0 1 y sin cos
0 0 1 y1
1
0 0 1 0 0 1 0 0 1
Useful compositions
Concatenation Properties
Matrix multiplication is associative.
AB C = (AB )C = A(B C)
i.e. 2 3 4 (2 3) 4 2 (3 4)
Concatenation Properties
Order of operations
With a graphics package that only provides a rotate function for revolving
objects about the coordinate origin, we can generate rotations about any
selected pivot point (x, y,) by performing the following sequence of
translate-rotate translate operations:
1. Translate the object so that the pivot-point position is moved to the coordinate
origin.
2. Rotate the object about the coordinate origin.
3. Translate the object so that the pivot point is returned to its original position.
xr , yr
1 0 xr cos sin 0 1 0 xr
0 1 yr sin cos 0 0 1 yr
0 0 1 0 0 1 0 0 1
T ( x , y ) R ( ) T ( x , y ) R ( x , y , )
r r r r r r
Translate-scale-translate
1 0 x s f x
0 0 1 0 x f
0 1 y 0 s 0 0 1 y
f y
f
0 0 1 0 0 1 0 0 1
sx 0 x f (1 sx )
0 sy y f (1 s y )
0 0 1
T ( x , y ) S ( s , s ) T ( x , y ) S ( x , y , s , s )
f f x y f f f f
x y
Examples on 2D Transformations
2 3 4 0 8 3
[X*]=[X][T]= =
8 10 0 1 32 10
Examples on 2D Transformations
2 1
[X]= 5 1
5 6
[T]=cos 45 sin 45
sin 45 cos 45
2 1 1 1 3 1
[X][T]= 5 1 2 2 = 1 6 4
1 1 2
5 6 11 1
2 2
A* 3 , 1 ,B* 6 , 4 , C* 11 , 1
2 2 2 2 2 2
Examples on 2D Transformations
Find the transformed point, P, caused by rotating P= (5, 1) about the origin
through an angle of 90 clockwise.
[P]=[P][T]
cos 90 sin 90
= 5 1 sin 90 cos 90
= 5 1 0 1
1 0
= 1 5
Examples on 2D Transformations
Examples on 2D Transformations
4 1 4 1
1 0
a) 5 2 0 1 = 5 2
4 3
4 3
4 1 4 1
b) 5 1 0 = 5 2
2 0 1
4 3
4 3
4 1 1 4
c) 5 0 1 =
2 1 0 2 5
4 3
3 4
4 1 1 4
0 1
d) 5 2 1 0 = 2 5
4 3 3 4
University Institute of Engineering (UIE)
Department of Computer Science and Engineering (CSE)
Examples on 2D Transformations
Examples on 2D Transformations
(1 2 3 3 2)
2 4 1 3
(
3 1 2 2 = 3
3 1
(3 3 1)
3
1 2 2 2
5 3 2 2
1
(5 3 3)
1
(5 3 3)
2 2
FAQ
References
Computer Graphics C Version, Donald Hearn and M.Pauline Baker
Pearson Education.
Computer Graphics Principles and Practice C.foley, VanDam, Feiner and
Hughes, Pearson Education
Thanks!