You are on page 1of 43

2D Geometric Transformations

Total Slide (51)

1
Geometric transformation means change in
 Place

 orientation

 Size

 Shape.

2
 2D Translations.
 2D Scaling

 2D Rotation

 2D shearing

 Matrix Representation of 2D transformation

Formula for Transformation

Matrix of Transformed object= Matrix of object in 2D * Matrix of transformation

3
Point P defined as P( x, y),
translate to Point P′( x′, y′) a distance d x parallel to x axis, d y parallel to y axis.
x′ = x + d x y ′ = y + d y
 x  x′  d x
P =   , P′ =   , T =  
 y  y′   dy 
Now P’
P
P′ = P + T

Original Point, Transformed point and Displacement in X and


Y can be written in the form of matrix

4
Y 6 

5
6

5

dx = 2 4
3
dy = 3 3 
3

2
1

0
1 2 3 4 5 6 7 8 9 10
X
 Component-wise addition
x  x '  dx 
v’ = v + t where v = , v ' = , t = 
y  y ' dy 

and x’ = x + dx
y’ = y + dy
To move polygons: translate vertices of polygon after adding translation factors
and redraw lines between them.

 Translation always Preserves lengths and shape of object (Distortion in object


shape will not occur).

5
Point P defined as P ( x, y ),
Perform a scale (stretch) to Point P′( x′, y′) by a factor s x along the x axis,
and s y along the y axis.
x′ = s x . x, y′ = s y . y
Define the matrix P’
P
sx 0
S=
0 s y 
Now
 x ′  s x 0  x 
P′ = S ⋅ P or  y′ =  0 . 
   s y   y

6
 After applying Scaling factor coordinates of
object is either increase or decrease. Expansion
and compression of object is depend upon the
scaling factor Sx and Sy.
 Uniform Scaling
 If Sx = Sy < 1 Uniform compression occurs.
 If Sx = Sy > 1 Uniform Expansion Will occur.
 If Sx=Sy=1 No Change will occur.
 Non uniform scaling
 If Sx ≠ Sy < 1 Non uniform compression occurs.
 If Sx ≠ Sy > 1 Non uniform expansion Will
occur.

7
 Uniform Scaling

 Non Uniform scaling

8
Y 6
5
s x =3 4
s y =2 3
2 6 9
2 2
2 3    
1 
1


1

0
1 2 3 4 5 6 7 8 9 10
X
 Component-wise scalar multiplication of vectors
x  x ' 
v’ = Sv where v = , v ' = 
y  y '
and
s x 0 x ' =s x x
S =
0 sy 
 y ' =s y y

9
2D case
 Add a 3rd coordinate to every 2D point. A point (a, b) in 2D can
be represented as (a,b,1) in homogeneous coordinate system.
Any point (x, y, w) where w!=0 represents a point at location
(x/w, y/w) in this coordinate system.
Point (2/3,4/3) can be represented in homogeneous coordinate
system (6,12,9)

3D Case
• Add a 4th coordinate to every 3D point. A point (a, b, c) in 3D can be
represented as (a,b,c,1) in homogeneous coordinate system.
Any point (x, y, z, w) in 3D where w!=0 represents a point at location
(x/w, y/w, z/w) in this coordinate system.
Example of Homogeneous
Coordinates

11
 Object coordinates are (00,10,11,01) Perform uniform expansion of this
object. Take scaling factor from your side.Draw final Figure also.

12
Q1. Write a 2X2 transformation matrix for each
of the following scaling transformation.
(1)The entire picture is 3 times as large.

(2)The entire picture is 1/3 as large.

(3)The X direction is 4 times as large and the y


direction unchanged.
(4) The x direction reduced to ¾ the original
and y direction increased by 7/5 times.

13
 Translate the square ABCD whose coordinates are A(0,0), B(3,0),c(3,3),
D(0,3).
 Translate this square 1.5 unit in x direction and 0.5 unit in y direction.
 After translation performing scaling with scaling factor sx=1.5 and
sy=0.5

14
 Find the transformation matrix that transforms
the square ABCD whose center is at (2,2) is
reduced to half of its size, with center still
remaining at (2,2). The coordinate of square
ABCD are A(0,0), B(0,4), C(4,4),D(4,0). Find the
coordinates of new square.

15
x' = x + t x
y' = y + t y
 Q: How can we represent translation as a
3x3 matrix?

 1 0 0
Translation =  0 1 0
tx ty 1
Example of translation
Homogeneous Coordinates

 x '  1 0 t x   x   x + t x 
 y ' = 0 1 t   y  =  y + t 
   y    y

 1  0 0 1   1   1 

tx = 2
ty = 1
 Prove that two scaling transformation is
commutative
Commutative property is
S1.s2=s2.s1
 Prove that two successive translation are additive.

 Prove that two successive scaling is multiplicative

18
 Composite 2D Translation (Two successive
Translation)

T = T(t x1 , t y1 ) ⋅ T(t x 2 , t y 2 )
= T(t x1 + t x 2 , t y1 + t y 2 )

 1 0 t x 2   1 0 t x1   1 0 t x1 + t x 2 
     
 0 1 t y 2  ⋅  0 1 t y1  =  0 1 t y1 + t y 2 
0 0 1  0 0 1  0 0 1 
     
Two Successive Translation is Additive
 Composite 2D Scaling (two successive
Scaling)

T = S( s x1 , s y1 ) ⋅ S( s x 2 , s y 2 )
= S( s x1s x 2 , s y1s y 2 )
 sx2 0 0   s x1 0 0   s x1 ⋅ s x 2 0 0
     
 0 sy2 0 ⋅ 0 s y1 0  =  0 s y1 ⋅ s y 2 0
 0 0 1   0 0 1   0 0 1 

Two Successive Scaling is Multiplicative
2D Rotation

21
y

P’(x’,y’)

r
P(x,y) x = r. cos φ
y = r. sin φ
θ y
r
φ
x
x

22
x′ = r. cos(θ + φ ) = r. cos φ . cosθ − r. sin φ . sin θ
y y′ = r. sin(θ + φ ) = r. cos φ . sin θ + r. sin φ . cosθ

P’(x’,y’)

P(x,y)
r x = r. cos φ
y = r. sin φ
θ y
r
φ
x
x

23
x′ = r. cos(θ + φ ) = r. cos φ . cosθ − r. sin φ . sin θ
y′ = r. sin(θ + φ ) = r. cos φ . sin θ + r. sin φ . cosθ
Substituting for r :
Rotation (Anticlockwise)
x = r. cos φ  x′  cosθ − sin θ   x 
y = r. sin φ  y′ =  sin θ . 
cosθ   y 
  
Gives us :
Rotation (Clockwise)
x′ = x. cos θ − y. sin θ
y′ = x. sin θ + y. cosθ  x′   cos θ sin θ   x 
 y′ = − sin θ . 
cos θ   y 
  
24
 Rotate a point (10,0) in anticlockwise direction
 Angle is 90 degree.

 After rotating this point rotate this point in


clockwise direction.

Rotation (Anti-Clockwise) Rotation (Clockwise)


 x′   x  cos θ − sin θ   x′   x   cos θ sin θ 
 y′ =  y   sin θ cos θ   y′ =  y  − sin θ cos θ 
       
25
 Example
 Find the transformed point, P’, caused by
rotating P= (5, 1) about the origin through an
angle of 90°.

cosθ − sin θ   x   x ⋅ cos θ − y ⋅ sin θ 


 sin θ •  = 
 cos θ   y   x ⋅ sin θ + y ⋅ cosθ 

5 ⋅ cos 90 − 1 ⋅ sin 90


= 
5 ⋅ sin 90 + 1 ⋅ cos 90

5 ⋅ 0 − 1⋅1
= 
5 ⋅1 + 1⋅ 0
− 1
= 
5
27
 What happens when you apply a rotation
transformation to an object that is not at the
origin?
 Solution:
 Translate the center of rotation to the origin
 Rotate the object
 Translate back to the original location
 In matrix form, it can be shown as

[ T ] = [ TR ] [ Rθ ] [ TR ]
−1

Here
 TR is Translation Matrix (Translation towards Origin)
 RƟ is Rotation Matrix (Rotation Matrix can be clockwise and
anticlockwise Rotation)
 TR-1 is Translation matrix (Away from origin)

29
Rotating About An Arbitrary Point
y y

x x

y y

x x
 Consider the square A(1,0) B(0,0) C(0,1) D(1,1).
Rotate the square ABCD by 90 degree
clockwise about A(1,0). Apply rotation about
arbitrary point to solve this question.

31
 Translation.
 P′=T + P
 Scale
 P′=S ⋅ P
 Rotation
 P′=R ⋅ P
 We would like all transformations to be
multiplications

32
 Translate [1,3] by [7,9]

1 0 7 1  8 
0 9   12
 1 ⋅3= 

0 0  
1  
1 1 

 Scale [2,3] by 5 in the X direction and 10 in the Y direction

5 0 0 2  10 
0 10 0⋅3 =30 
   
 

0 0  
1  
1 1 


Rotate [2,2] by 90° (π/2)

cos(π/ 2) −sin(π/ 2) 0 2 0 −1 0 2 −2


sin(π/ 2) cos(π/ 2) 0⋅2=1 0 0⋅2=2 
         

 0 0 1
 
1
 
0 0 1 1 
   
1 

33
Shearing Transformation
The shearing transformation when applied to the object it results
distortion of shape.

Types of Shearing Transformation

X- shear: In X-shear y coordinate remain unchanged, but x is


changed.
Y- shear: In Y-shear x coordinate remain unchanged, but y is
changed
 x '  x   1 0
 y ' =  y   shx 1   x '  x   1 Shy 
      y ' =  y  0 1 
    
X- Shear Y- Shear
34
 Shear following object 2 unit in x direction and
2 unit in y direction.

 Object coordinates are (00,10,11,01).

35
 Basic 2D transformations as 3x3 matrices

 x '  1 0 t x   x   x '  s x 0 0  x 
 y ' = 0 1 t   y   y ' =  0 sy 0  y 
   y     
 1  0 0 1   1   1   0 0 1  1 

Translate Scale

 x' cos Θ − sin Θ 0  x   x '  1 shy 0  x 


 y ' =  sin Θ 0  y   y ' =  sh
   cos Θ
   x 1 0  y 
 1   0 0 1  1   1   0 0 1  1 

Rotate Shear
 Transformations can be combined by
matrix multiplication

 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

p’ = T(tx,ty) R(Θ) S(sx,sy) p
 Rotation with respect to a pivot point (x,y)

Object * T (− x, − y ) ×R (θ ) ×T ( x, y )
 1 0 − x   cos θ − sin θ 0 1 0 x 
 ÷ ÷ ÷
= Object *  0 1 − y ÷× sin θ cos θ 0 ÷× 0 1 y ÷
0 0 1 ÷  0 0 1÷  ÷
    0 0 1 
 Steps for Fix point Scaling

 Translate point to origin (Fig (b))


 Perform Scaling Fig(c) Expansion or
compression
 Inverse Translation Fig(d)

39
 Scaling with respect to a fixed point (x,y)

Object * T (− x, − y ) ×S ( sx , s y ) ×T ( x, y )
 1 0 0   sx 0 0 1 0 0
 ÷ ÷ ÷
= Object *  0 1 0 ÷× 0 sy 0 ÷× 0 1 0 ÷
 −x − y 1 ÷  0 0 1 ÷  x y 1 ÷
  
 Q1. Magnify the triangle with vertices A(0,0),
B(1,1), C(5,2) to twice its size while keeping
c(5,2) fixed.

41
 Composite 2D Rotation (Two Successive
Rotation)
T = R (θ 2 ) ⋅ R (θ1 )
= R (θ 2 + θ1 )

 cos θ 2 − sin θ 2 0   cos θ1 − sin θ1 0   cos(θ 2 + θ1 ) − sin(θ 2 + θ1 ) 0 


     
 sin θ 2 cos θ 2 0  ⋅  sin θ1 cos θ1 0  =  sin(θ 2 + θ1 ) cos(θ 2 + θ1 ) 0 
 0 0 1   0 0 1   0 0 1 

Two Successive Rotation is Additive


Thanks !!

43

You might also like