3 Transformations
3 Transformations
3 Transformations
2D Transformations
y
x
Applications:
- Animation
x y - Image/object manipulation
- Viewing transformation
- etc.
2
2D Transformation
• Transformations : -
1. GEOMETRIC
2. COORDINATE
• We have two alternatives, either the geometric
objects are transformed or the coordinate system is
transformed.
3
Geometric Transformations
• Geometric Transformations
– Position (translation) Translations and Reflection
– Size (scaling)
– Orientation (rotation)
– Shapes (shear)
• Various Geometric transformations are :
– Translation
– Rotation
– Scaling
– Refloection
– Searing
4
Point Representation
5
1. Translation
• Re-position a point along a straight line
• Given a point (x,y), and the translation distance
(tx,ty)
The new point: (x’, y’) (x’,y’)
x’ = x + tx
ty
y’ = y + ty (x,y)
tx
OR P’ = P + T where P’ = x’ p= x T= tx
y’ y ty
6
2. Rotation
A) About Origin
• Default rotation center: Origin (0,0)
Rotate clockwise
o x
7
Rotation contd...
(x,y) -> Rotate about the origin by (x’,y’)
8
Rotation contd..
(x,y) -> Rotate about the origin by y
(x’,y’)
in anticlockwise direction
(x,y)
r
How to compute (x’, y’) ?
o
x
9
Rotation contd...
(x’,y’)
x = r cos () y = r sin ()
x’ = r cos () y = r sin () (x,y)
r
x’ = r cos ()
= r cos() cos() – r sin() sin()
= x cos() – y sin()
y’ = r sin ()
= r sin() cos() + r cos()sin()
= y cos() + x sin()
10
Rotation contd...
(x’,y’)
x’ = x cos() – y sin()
(x,y)
y’ = y cos() + x sin()
r
Matrix form?
x’ =
cos() -sin() x
y’ sin() cos() y
3 x 3?
11
B) Fixed (Pivot) Point Rotation
(px,py)
12
Fixed (Pivot) Point Rotation
contd...
• To rotate about an arbitrary point P (px,py) by :
– Translate the object so that P will coincide with the
origin: T(-px, -py)
(px,py)
13
Fixed (Pivot) Point Rotation
contd...
• To rotate about an arbitrary point P (px,py) by :
– Translate the object so that P will coincide with the
origin: T(-px, -py)
– Rotate the object: R()
(px,py)
14
Fixed (Pivot) Point Rotation
contd...
• To rotate about an arbitrary point P (px,py) by :
– Translate the object so that P will coincide with the
origin: T(-px, -py)
– Rotate the object: R()
– Translate the object back: T(px,py)
(px,py)
15
Fixed (Pivot) Point Rotation
contd...
Step 1: Translate the object so that P will coincide
with the origin: T(-px, -py)
Step2: Rotate the object: R()
Step 3: Translate the object back: T(px,py)
x’ = x . Sx x’ Sx 0 x
=
y’ = y . Sy y’ 0 Sy y
(4,4)
(2,2) Sx = 2, Sy = 2
(2,2)
(1,1)
17
Scaling contd...
(4,4)
(2,2) Sx = 2, Sy = 2
(2,2)
(1,1)
18
B )Pivot point Scaling contd...
(px,py)
19
Pivot point Scaling contd...
(px,py)
21
Pivot point Scaling contd...
(px,py)
22
Pivot point Scaling contd...
(px,py)
23
Pivot point Scaling contd...
(px,py)
24
Put Translation, Rotation, Scaling together
• Translation:
x x t x
y y t y
• Rotation:
x cos sin t x
y sin cos t y
• Scaling:
x s x 0 tx
y 0 sy t y
25
Homogeneous coordinates 1
• Uniform representation is required of translation,
rotation, scaling
• Uniform representation of object points and
transformation matrices
• Add extra coordinate to the point
x = (x, y, h) where h=1
H&B 7-2:225-228
Translation, Rotation , Scaling (Homogeneous system)
Translation : Rotation :
x' 1 0 t x x x' cos sin 0 x
y '
0 1 t y y y ' sin cos 0 y
1 0 0 1 1 1 0 0 1 1
or or
P ' T(t x , t y )P P ' R ( )P
Scaling :
x' sx 0 0 x
y' 0 sy 0 y
1 0 0 1
1
or
P ' S( s x , s y )P
27
4. Reflection
1. Reflction abt X axis
2. Reflection ant Y axis
y
3. Reflection abt X=Y line
4. Reflection abt X=-Y line
5. Reflect X=5 line
6. Reflection Y=mX+c line
x
1 0 x x
Shy
sh
y 1 y shy .x y
Beware!
• Matrix multiplication is not commutative
• The order of the transformations is vital
– Rotation followed by translation is very different from
translation followed by rotation
– careful with the order of the matrices!
• Small commutativity:
– rotation commute with rotation, translation with
translation…
Numericals
1. Rotate a unit square with diagonal points as (0,0) , (-1,-1) by angle 30
degree, anticlockwise.
2. Rotate a triangle A(10,5), B(5,7), C(12,10) by 45 degree clockwise such
that point A is taken to (10,10)
3. Apply fixed point rotation on a rectangle A(10,10),B(5,5), C(5,2),D(7,7)
so that point B is fixed after rotation.
4. Reflect given triangle A,B,C, about a line X=3
5. Reflect a unit square with diagonal points A(0,10) B(1,9) about Y=X line.
33