2 D Transformation: Computer Graphic
2 D Transformation: Computer Graphic
2 D Transformation
Outline
1. Why transformations ?
2. Basic 2D Transformations
Translation
Scaling
Rotation
3. Homogeneous Coordinate system
4. Composite Transformations
5. Reflection and Shearing
Why transformations ?
x x Tx
y 6 y y Ty
5
4
x Tx x
y T y
3
1
y
0
1 2 3 4 5 6 7 8 9 10
x
Note: House shifts position relative to origin
2D Translation
5 10 15 20 x 5 10 15 20 x
(a) (b)
Basic 2D Transformations
2. Scaling
5 y S y y
4
3 6 9
x S x 0 x
y 0
3 3
S y y
2
1 2
1
3
1
0
1 2 3 4 5 6 7 8 9 10
x
Note: House shifts position relative to origin
Example: Non- Uniform Scaling
(a)
(b)
Non-uniform scaling
Basic 2D Transformations
3. Rotation
x r cos ( x, y)T
y r sin
x r cos( ) ( x, y)T
r
x r cos cos r sin sin r
x x cos y sin
y ' r sin( )
sin(a+b) = sin(a)cos(b) + sin(b)cos(a)
Similarly, cos(a+b) = cos(a)cos(b) - sin(a)sin(b)
y y cos x sin
3. Rotation
0 1 1 0
v [A B C D] 0 0 1 1
1 1 1 1
1 1
2 - 2 0
cos 45 sin 45 0
1 1
TRotate sin 45 cos 45 0 0
2 2
0 0 1
0 0 1
1 1 1 1
2 - 2 0 0 2
0 -
2
0 1 1 0
1 1 1 2 1
v 0 0 0 1 1 0
2 2 2 2 2
1 1 1 1
0 0 1 1 1 1 1
3. Rotation
y
6
2
1 6
0
1 2 3 4 5 6 7 8 9 10
x
2D Transformations in Homogenous Notation
x' S x 0 0 x
2. Scaling y ' 0 Sy 0 y
1 0 0 1 1
x' 1 0 Tx x
y ' 0 1 T y
3. Translation y
cos sin 0
T 1rotation sin cos 0
1. Inverse of Rotation
0 0 1
1
S 0 0
x
1
T 1Scale 0 0
2. Inverse of Scaling Sy
0 0 1
1 0 Tx
T 1Translate 0 1 Ty
3. Inverse of Translation
0 0 1
Example
Consider the line with endpoints (10, 10) and (30, 25).
Translate it by tx = -20, ty = -10 and then rotate it by θ = 90º.
y
(30, 25)
(10, 10)
x
Right-to-left
x cos 90 sin 90 0 1 0 20 x
y
sin 90 cos 90 0 0 1 10 y
1 0 0 0 1 1
0 1
Solution
0 1 0 1 0 20 x
1 0 0 0 1 10 y
0 0 1 0 0 1 1
0 1 10 x y
1 0 20 y (30, 25)
0 0 1
1
(10, 10)
x
Solution (continue)
y
x 0 1 10 x (30, 25)
(-15, 10)
y
1 0 20 y (10, 10)
x
1 0 0 1
1 (0, -10)
x 0 1 10 10 0
Point (10, 10) y
1 0 20 10
10
1 0 0 1 1
1
x 0 1 10 30 15
Point (30, 25) y
1 0 20 25
10
1 0 0 1
1 1
Exercises
Consider the following object:
25
10
10 45 x
[ Sc ]
S x 0 0 [Tr ]1 (xc, yc)T
TScale 0 Sy 0
1 0 xr
0 1
T 1Translate 0 1 yr
0
0 0 1
S x 0 xr ( S x 1)
TComposite 0 S y yr ( S y 1)
0 0 1
x x
y [T ] y
composite
1 1
Example1:
Consider a triangle having a vertices at A(0,0), B(5,1), and
C(3,4) scale this triangle using scaling factors Sx=2 and
Sy=1 about a) the origin b) about the reference point (2,3)
a) At origin ( xr=0, yr=0)
S x 0 xr ( S x 1) 2 0 0
TComposite 0 Sy yr ( S y 1) 0 1 0
0 0 1 0 0 1
0 5 3
v [A B
C ] 0 1 4
1 1 1
2 0 0 0 5 3 0 10 6
v Tcomposite *v 0 1 0 * 0 1 4 0 0 4
0 0 1 1 1 1 1 1 1
b) Scaling about the reference point (2,3) : Here, the transformation matrix
S x 0 xr ( S x 1) 2 0 2
TComposite 0 Sy yr ( S y 1) 0 1 0
0 0 1 0 0 1
2 0 2 0 5 3 2 12 8
v Tcomposite *v 0 1 0 * 0 1 4 0 1 4
0 0 1 1 1 1 1 1 1
Rotation about an Arbitrary Point
Rotation about an arbitrary point is composite
transformation . This operation involve s three basic
transformations:
1. Translation of the object center (xc,yc) to the origin
2. Rotation of the object about the origin by angle θ
in.say, the anticlockwise direction
3. Translation of the rotated object back to its original
position 1
Tcomposite TtransTRotTTrans
x x
y [T ] y
composite
1 1
House (H ) T (Tx, Ty ) H
1 2 1 0 xr
TTranslate 0 1 yr
0 0 1
cos sin 0 1 0 xr
TRotate sin cos 0 T 1Translate 0 1 yr
3
0 0 1 4 0 0
1
Example: Consider a triangle having a vertices at A(0,0),
B(5,1), and C(3,4) scale this triangle. Rotate the triangle by
90 about a) the origin b) about the reference point (2,3)
cos 90 sin 90 0 0 - 1 0
TRotate sin 90 cos 90 0 1 0 0
0 0 1 0 0 1
v TRot v
0 - 1 0 0 5 3 0 - 1 - 4
v 1 0 0 0 1 4 0 5 3
0 0 1 1 1 1 1 1 1
b) Rotation about point (2,3 )
1
Tcomposite T T T
trans Rot Trans
1 0 - 2 0 - 1 0 1 0 2
Tcomposite 0 1 - 3 1 0 0 0 1 3
0 0 1 0 0 1 0 0 1
1 0 - 2 0 - 1 - 3 0 - 1 - 5
Tcomposite 0
1 - 3 1 0 - 2 1 0 - 5
0 0 1 0 0 1 0 0 1
v TComposite v
0 - 1 - 5 0 5 3 - 5 - 6 - 9
v 1 0 - 5 0 1 4 - 5 0 - 2
0 0 1 1 1 1 1 1 1
Exercises
Consider the following object:
y
25
10
10 45 x
x 1 0 0 x
y
0 1 0 y
x
1 0 0 1 1
Reflection of an object about the x axis
About the y axis
y
x 1 0 0 x
y
0 1 0 y
1 0 0 1 1
x
1 1
Tcomposite TtransTRotTref T T Rot trans
Example: Consider a triangle whose vertices are (2 2), (4 2) and (4
4). Find the concatenated transformation matrix and the
transformed vertices for rotation of 90 about the origin followed
by reflection through the line y = -x. Comment on the sequence of
transformations.
0 1 0
Trot90 1 0 0
0 0 1
0 1 0
Tref y x 1 0 0
0 0 1
Ex: Reflect triangle (2,4),(4,6),(2,6) about line
y=0.5(x+4)
0.894 0.44721 0
TTr ( ) 0.44721 0.894 0
0 0 1
5. Translate back (0,2) 1 0 0
TTr 0 1 2
0 0 1
[T ] [Ttr ][Trot ][Tref ][Trot ]1[Ttr ]1
1 0 0 0.894 0.44721 0 1 0 0 0.894 0.44721 0 1 0 0
[T ] 0 1 2 0.44721 0.894 0 0 1 0 0.44721 0.894 0 0 1 2
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1
[v' ] [T ][v]
0.6 0.8 1.6 2 4 2 2.8 5.6 4.4
[v' ] 0.8 0.6 3.2 4 6 6 2.4 2.8 1.2
0 0 1 1 1 1 1 1 1
Shearing about the origin
y y y
(1, 3)
(1, 2)
(1, 1) (2, 1) (3, 1)
(0, 1) (0, 1)
x x x
(0, 0) (1, 0) (0, 0) (1, 0) (0, 0)
1 SH x SH x yref
Tshearx 0 1 0
0 0 1
1 0 0
Tsheary SH y 1 SH y xref
0 0 1
Shear Example