New-Week 5 2D Transformations
New-Week 5 2D Transformations
2D Transformations
1
Transformation
Transform every point on an object according to certain rule.
Q (x’, y’)
P (x,y)
T
Initial Object
Transformed Object
(20,35)
(45,30)
(65,30)
x x tx
(10,5) (30,5)
y y t y
The vector (tx, ty) is called the offset vector.
Rotation About the Origin
y
(x’,y’)
(x’,y’)
(x,y)
(x,y)
o x
x x cos y sin
y x sin y cos
The above 2D rotation is actually a rotation about the z-axis (0,0,z) by
an angle .
Rotation About a Pivot Point
(x’,y’) (x,y)
(xp , yp)
Pivot Point
(x1, y1)
(xp , yp)
x1 x x p
y1 y y p
Rotation About a Pivot Point
x 2 x1 cos y1sin
y 2 x1 sin y1 cos
Rotation About a Pivot Point
STEP-3: Translate the pivot point to original position
(x’, y’)
(x2, y2)
(xp, yp)
x x 2 x p
y y 2 y p
Scaling About the Origin
(x’,y’)
(x,y)
x x. s x
(x,y)
(x’,y’)
y y. s y
Uniform Non-Uniform
Uniform: sx s y Non-Uniform: sx s y
Scaling About a Fixed Point
(xf , yf )
x ( x x f ).s x x f
y ( y y f ).s y y f
Reflections
y
Reflection about y Initial
Object
x = x
Reflection about
origin
Reflection about x
x = x
y = y
y = y
Shear
x x hx y
y y
a b
c d
• Apply the Transformation to a Point
x ax by x a b x
y cx dy y c d y
Transformation
Point
Matrix
2×2 Matrices
2D Scaling
x sx x x sx 0 x
y sy y y 0 sy y
2×2 Matrices
2D Rotation
2D Shearing
x x x 1 0 x
y y y 0 1 y
Matrix Representations
x x t x
Translation y y t
y
Rotation [Origin]
x cos sin x
y sin cos y
x sx 0 x
Scaling [Origin] y 0 s y
y
Matrix Representations
x 1 0 x
Reflection about x y 0 1 y
x 1 0 x
Reflection about y
y 0 1 y
Reflection about x 1 0 x
the Origin y 0 1 y
Matrix Representations
x 1 0 tx x
x x tx y 0 1 ty y
y y ty
1 0 0 1 1
P ' T (t x , t y ) P
• Homogeneous coordinate representation of 2D Rotation
x cos sin 0 x
y sin cos 0 y
1 0 0 1 1
If, x x then, x x
y [T ] y y [T ] 1 y
1 1 1 1
1
Examples: T (t x , t y ) T ( t x , t y )
R 1 ( ) R( )
1 1
S ( s x , s y ) S ,
1
s s
x y
H x 1 (h) H x ( h) [6]-30
Transformation Matrices
Additional Properties:
T (t x , t y )T (u x , u y ) T (t x u x , t y u y )
R (1 ) R ( 2 ) R (1 2 )
R ( ) 1
S ( s x , s y ) S ( wx , wy ) S ( s x wx , s y wy )
Composite Transformations
Transformation T followed by x x
Transformation Q followed by y [ R ][Q ][T ] y
Transformation R:
1 1
x 1 0 x f sx 0 0 1 0 x f x
y 0 1
0 0 1 y f y
yf 0 sy
1 0 0 1 0 0 1 0 0 1 1
Order of Transformations
Order of Transformations
In composite transformations, the order of
transformations is very important.
Rotation followed by Translation:
x 1 0 tx cos θ - sinθ 0 sx 0 0 x
y 0 1 ty sinθ cosθ 0 0 sy 0 y
w 0 0 1 0 0 1 0 0 1 w
0 0 1 0 0 1 0 0 1 0 0 1
Rotation about the point (2,3) by +90
P’=
P’==