UNIT -2
Two-Dimensional Transformations
2D Transformations
 What is transformations?
 Changes in orientation , size , and shape are accomplished
with geometrical transformations that alters the coordinate
description of object.
 Why the transformations is needed?
 To manipulate the initially created object and to display the
modified object without having to redraw it.
 2 ways
 Object Transformation
• Alter the coordinates descriptions an object
• Translation, rotation, scaling etc.
• Coordinate system unchanged
 Coordinate transformation
• Produce a different coordinate system
2D Transformations
4
Transformations and Matrices
 Transformations are functions
 Matrices are functions representations
 Matrices represent linear transformation
 {2x2 Matrices}  {2D Linear Transformation}
 What are they?
 changing something to something else via rules
 mathematics: mapping between values in a range set and
domain set (function/relation)
 geometric: translate, rotate, scale, shear,…
 Why are they important to graphics?
 moving objects on screen / in space
 mapping from model space to screen space
 specifying parent/child relationships
Basic Transformations : Translation (1/2)
 Translation
 Definition : repositioning objects along a straight line path
from one position to another
 Let : original position, : new position
 We need translation distance (translation vector)
for x direction
for y direction
 Then,






y
x
=P 








y
x
=P
T =
t
t
x
y






x' x t
y' y t
x
y
 
 
Translation (2/2)
 In matrix form
 Translation is rigid-body Transformation that moves
objects without deformation
• every point on the object is translated by the same amount
 For straight line
• applying translation distance to each line end points
 For polygon, curves
P' P T
x
y
t
t
x
y
  





 






Basic Transformation : Rotation
Basic Transformations : scaling (1/2)
 Scaling
 Definition : alters the size of an objects
 we need scaling factors
: for x value
: for y value
 In matrix form
 Then
 if : Uniform scaling
: differential scaling
S
S 0
0 S
X
y







x x sx'  y y sy' 













y
x
s0
0s
PSP
y
x
s s
s s
x y
x y


scaling (2/2)
 if : uniform compression
• move objects to the coordinate origin
 if : uniform Enlargement
• move objects farther from the origin
 Fixed point scaling : scaling based on a fixed point
• An object is scaled relative to the fixed point by scaling distance
from each vertex to fixed point
• when
0 s s 1x y  
1 s sx y 
( ),x yf f
x' x (x x )s x s x (1 s )
y' y (y y )s y s y (1 s )
f f x x f x
f f y y f y
      
      
(x ,y) (0,0)f f 
18
Inverse 2D - Transformations
y
-
y
x
-
x
),(
-
(sx,sy)
(-θ
-
(θ
(-dx,-dy)
-
(dx,dy)
MM
MM
SS
RR
TT
sysx





1
1
1
)
1
)
1
:RefMirror
:Sclaing
:Rotation
:nTranslaito
11
19
Homogeneous Co-ordinates (1/3)
 Translation, scaling and rotation are expressed
(non-homogeneously) as:
translation: P = P + T
Scale: P = S · P
Rotate: P = R · P
 Composition is difficult to express, since translation
not expressed as a matrix multiplication
 Homogeneous coordinates allow all three to be expr
essed homogeneously, using multiplication by 3 ´ 3
matrices
 W is 1 for affine transformations in graphics
20
Homogeneous Co-ordinates (2/3)
 P2d is a projection of Ph onto the w = 1
plane
 So an infinite number of points correspon
d to : they constitute the whole line
(tx, ty, tw)
x
y
w Ph(x,y,w)
P2d(x,y,1)
w=1
Homogeneous Coordinates (3/3)
 For Translation, Rotation, Scaling


































1
y
x
100
t10
t01
s
y
x
y
x


























1
y
x
100
0cossin
0sin-cos
s
y
x




































1
y
x
100
0s0
00s
s
y
x
y
x
Translation:
Scaling:
Rotation:
22
Classification of Transformations
1. Rigid-body Transformation
 Preserves parallelism of lines
 Preserves angle and length
 e.g. any sequence of R() and T(dx,dy)
2. Affine Transformation
 Preserves parallelism of lines
 Doesn’t preserve angle and length
 e.g. any sequence of R(), S(sx,sy) and T(dx,dy)
unit cube 45 deg rotaton Scale in X not in Y
23
Properties of rigid-body transformation










100
2221
1211
y
x
trr
trr
The following Matrix is Orthogonal if the upper left 2X2 matrix has the
following properties
1.A) Each row are unit vector.
sqrt(r11* r11 + r12* r12) = 1
B) Each column are unit vector.
sqrt(c11* c11 + c12* c12) = 1
2.A) Rows will be perpendicular to each other
(r11 , r12 ) . ( r21 , r22) = 0
B) Columns will be perpendicular to each other
(c11 , c12 ) . (c21 ,c22) = 0
e.g. Rotation matrix is orthogonal









 
100
0cossin
0sincos


• Orthogonal Transformation  Rigid-Body Transformation
• For any orthogonal matrix B  B-1 = BT
Concatenation properties.
 Matrix multiplication : associative
• ex) For three matrices A, B and C
• Translation or Rotation : additive property commutative
• scaling : multiplicative property commutative
 However, Translation and Rotation : non commutative
• order of transformation matrix multiplication is important
A B C (A B) C A (B C)       
ABBA 
26
Commutative of Transformation Matrices
• In general matrix multiplication is not commutative
• For the following special cases commutativity holds i.e. M1.M2 = M2.M1
M1 M2
Translate Translate
Scale Scale
Rotate Rotate
Uniform Scale Rotate
• Some non-commutative
Compositions:
 Non-uniform scale, Rotate
 Translate, Scale
 Rotate, Translate
Original
Transitional
Final
Composite Transformation (1/2)
 Translation
 If two successive translation factor (tx1, ty1) and (tx2, ty2) are
applied to a coordinate point P
• then
• ex)
i.e,
 Two successive Translation are additive
1 0 t
0 1 t
0 0 1
1 0 t
0 1 t
0 0 1
1 0 t t
0 1 t t
0 0 1
x2
y2
x1
y1
x1 x2
y1 y2


































P' T (t ,t ) {T (t ,t ) P} {T (t ,t ) T (t ,t )} P2 X2 y2 1 x1 y1 2 X2 y2 1 x1 y1     
T(t ,t ) T(t ,t ) T(t t ,t t )x2 y2 x1 y1 x1 x2 y1 y2   
Composite Transformation (2/2)
 Rotation
 two successive rotation
 two successive rotations are also additive
 Scaling
 successive scalings are multiplicative
P)}R(){R(P}){R()R(P 1212  
)R()R()R( 2121  
P' R( ) P1 2   
  ,

































100
0ss0
00ss
100
0s0
00s
100
0s0
00s
y2y1
x2x1
y1
x1
y2
x2
S(S ,S ) S(S ,S ) S(S S ,S S )X2 Y2 X1 Y1 X1 X2 Y1 Y2   
General pivot-point Rotation (1/2)
 Rotation about arbitrary point p (xr, yr)
 step1) Translate P to origin
 step2) Rotation about origin
 step3) Retranslation to position P.
General pivot-point Rotation (2/2)
 Composite transformation matrix
 
 
  


  
 
 
  


  
x
y
x
y
x y
y x
r
r
r
r
r r
r r

































  
 










cos sin
sin cos
cos sin ( cos ) sin
sin cos ( cos ) sin
 
 
   
   
),y,R(x),-yT(-x)R()y,T(x rrrrrr  
General Fixed Point Scaling
General Fixed-Point Scaling
 Scaling about arbitrary point p(xr, yr)
 step 1) translate p to origin
 step 2) scaling about origin
 step 3) Retranslate to position P
 
 
  
 
 
  
 
 
  
 
 
  
x
y
s
s
x
y
s x s
s y s
r
r
x
y
r
r
x r x
y r y













































( )
( ) )ss,y,S(x),-yT(-x)sS(s)y,T(x yxffffyxff ,, 
Other Transformations : Reflection (1/3)
 Reflection : produce a mirror images of an object
 We need axis of reflection
 rotating the objects 180°about reflection axis
 Reflection about the x axis: Just flip the y coordinate
 Reflection about the y axis: Just flip the x coordinate
 Reflection about the origin, flip both coordinates
1
32
1
32
1
32
1’
3’2’
1’
2’3’
1’
2’3’
Reflection about x axis Reflection about y axis Reflection about origin
Reflection (2/3)
R
1 0 0
0 1 0
0 0 1
y 










R
1 0 0
0 1 0
0 0 1
X  









 












100
010
001
R0
Reflection (3/3)
 Reflection through arbitrary point P (xr, yr)
• translate point p to origin : Tr
• perform reflection about origin : Ro
• retranslate to original position : Tr
 Reflection through y=x line


































100
y10
x01
100
010
001
100
y10
x01
r
r
r
r
0 1 0
1 0 0
0 0 1










Reflection through an arbitrary line y=Lx+b
Shear Transformation
 Shear : distorts the shape of an object
 Shear transformation that distorts the shape of an object such that the
transformed shape appears as if the object were composed of internal
layers that had been caused to slide over each other.
 Shearing (slide over) can be in either x or y direction
 In X Shear, x-values changes along x-direction by shearing factor of shx
• point is shifted by horizontally by an amount proportional to its
distance from x-axis
• y values are unchanged
 In Y Shear, y-values changes along y-direction by shearing factor of shy
• point is shifted by vertically by an amount proportional to its distance
from y-axis
• x values are unchanged
X - Shear
Transformation matrix of X- Shear
• So,
• Transformed positions
T
1 sh 0
0 1 0
0 0 1
shx
x











x' x sh yx   ,
y' y
X –Shear relative to y- reference line
Transformation matrix of X- Shear with y- reference line
 X-direction shearing relative to liney yref
1 sh sh y
0 1 0
0 0 1
x x ref









yy'
)y(yshxx' refx


Y - Shear
y-direction










100
01sh
001
y
(x)shyy'
xx'
y

The transformation matrix for y-shear and its equation
Y – Shear relative to x reference line
 y-direction shearing relative to linex xref
1 0 0
sh 1 sh x
0 0 1
y y ref










x' x
y' y sh (x x )y ref

  
 The area of the parallelogram can be calculated as,
 Area of the trapezium =(sum of two parallel side)*h / 2
 Parea = (a+c) (b+d) – (ab) – (cd) – (b+b+d) – (c+a+c)
= ad – bc
= det
 Thus, area of any parallelogram is formed by transforming
a square which is a function of the transformation matrix
determinant and is related to the area of the initial square
Parea = Sarea (ad-bc) = Sarea det [T]
 Area of any transformed figure Tarea is related to the ar
ea of the initial figure Iarea by,
Tarea = Iarea (ad-bc)
2
1
2
1
2
c
2
b






dc
ba
WINDOW TO VIEW PORT TRANSFORMATION
ASSIGNMENT -2 TWO –D TRANSFORMATION
Assigned Date : 26-02-13
Submission Date : 05-03-13
 Fo r a l l t h e b e l o w g i v e n pr o b l e m Or i g i n a l a n d
Fi n a l po s i t i o n d i a g r a m i s n e c e s s a r y
1. Scale a square at [(2, 2), (6, 6)] along one of its diagonal and find the
new vertices.
2. Perform a clockwise 30 degree rotation of a triangle A (2, 3), B (5, 5),
C(4,3) about the point (1,1)
3. Find a transformation of triangle A (1, 0), B (0, 1), C (1, 1) by
a) Rotating 30 degree about the origin and then translating one
unit in x and y direction.
b) Translating one unit in x and y direction and then rotating 30
degree about the origin.
4. Represent a triangle at [(3, 3), (5, 6) , (7,3) ] in a new coordinate
system with origin at (3,3) and its x-axis making an angle +45 degree
with the x-direction of the base coordinate system.
5. Find out the co-ordinate of a figure bounded by (0,0) , (1,5) , (6,3) (-
3,-4) when reflected along the line whose equation is y=1 (x+5) and
sheared by 2 units in
x –direction and 2 units in y-direction.
[HINT: Ref -Page No. 3-46 in Godse Book]
6. Compute the new reflected coordinates of a point (-4,-4), when
reflected with respect to a line that passes through (-4, 0) and (0,-4)
[HINT: Ref -Page No. 3-62 in Godse Book]
7. For a point (2, 4) in a window at [(1, 1), (5, 5)], find the equivalent
point in the View Port at [(1, 1), (5, 10)].

Two dimensionaltransformations

  • 1.
  • 2.
    2D Transformations  Whatis transformations?  Changes in orientation , size , and shape are accomplished with geometrical transformations that alters the coordinate description of object.  Why the transformations is needed?  To manipulate the initially created object and to display the modified object without having to redraw it.
  • 3.
     2 ways Object Transformation • Alter the coordinates descriptions an object • Translation, rotation, scaling etc. • Coordinate system unchanged  Coordinate transformation • Produce a different coordinate system 2D Transformations
  • 4.
    4 Transformations and Matrices Transformations are functions  Matrices are functions representations  Matrices represent linear transformation  {2x2 Matrices}  {2D Linear Transformation}  What are they?  changing something to something else via rules  mathematics: mapping between values in a range set and domain set (function/relation)  geometric: translate, rotate, scale, shear,…  Why are they important to graphics?  moving objects on screen / in space  mapping from model space to screen space  specifying parent/child relationships
  • 11.
    Basic Transformations :Translation (1/2)  Translation  Definition : repositioning objects along a straight line path from one position to another  Let : original position, : new position  We need translation distance (translation vector) for x direction for y direction  Then,       y x =P          y x =P T = t t x y       x' x t y' y t x y    
  • 12.
    Translation (2/2)  Inmatrix form  Translation is rigid-body Transformation that moves objects without deformation • every point on the object is translated by the same amount  For straight line • applying translation distance to each line end points  For polygon, curves P' P T x y t t x y                
  • 13.
  • 16.
    Basic Transformations :scaling (1/2)  Scaling  Definition : alters the size of an objects  we need scaling factors : for x value : for y value  In matrix form  Then  if : Uniform scaling : differential scaling S S 0 0 S X y        x x sx'  y y sy'               y x s0 0s PSP y x s s s s x y x y  
  • 17.
    scaling (2/2)  if: uniform compression • move objects to the coordinate origin  if : uniform Enlargement • move objects farther from the origin  Fixed point scaling : scaling based on a fixed point • An object is scaled relative to the fixed point by scaling distance from each vertex to fixed point • when 0 s s 1x y   1 s sx y  ( ),x yf f x' x (x x )s x s x (1 s ) y' y (y y )s y s y (1 s ) f f x x f x f f y y f y               (x ,y) (0,0)f f 
  • 18.
    18 Inverse 2D -Transformations y - y x - x ),( - (sx,sy) (-θ - (θ (-dx,-dy) - (dx,dy) MM MM SS RR TT sysx      1 1 1 ) 1 ) 1 :RefMirror :Sclaing :Rotation :nTranslaito 11
  • 19.
    19 Homogeneous Co-ordinates (1/3) Translation, scaling and rotation are expressed (non-homogeneously) as: translation: P = P + T Scale: P = S · P Rotate: P = R · P  Composition is difficult to express, since translation not expressed as a matrix multiplication  Homogeneous coordinates allow all three to be expr essed homogeneously, using multiplication by 3 ´ 3 matrices  W is 1 for affine transformations in graphics
  • 20.
    20 Homogeneous Co-ordinates (2/3) P2d is a projection of Ph onto the w = 1 plane  So an infinite number of points correspon d to : they constitute the whole line (tx, ty, tw) x y w Ph(x,y,w) P2d(x,y,1) w=1
  • 21.
    Homogeneous Coordinates (3/3) For Translation, Rotation, Scaling                                   1 y x 100 t10 t01 s y x y x                           1 y x 100 0cossin 0sin-cos s y x                                     1 y x 100 0s0 00s s y x y x Translation: Scaling: Rotation:
  • 22.
    22 Classification of Transformations 1.Rigid-body Transformation  Preserves parallelism of lines  Preserves angle and length  e.g. any sequence of R() and T(dx,dy) 2. Affine Transformation  Preserves parallelism of lines  Doesn’t preserve angle and length  e.g. any sequence of R(), S(sx,sy) and T(dx,dy) unit cube 45 deg rotaton Scale in X not in Y
  • 23.
    23 Properties of rigid-bodytransformation           100 2221 1211 y x trr trr The following Matrix is Orthogonal if the upper left 2X2 matrix has the following properties 1.A) Each row are unit vector. sqrt(r11* r11 + r12* r12) = 1 B) Each column are unit vector. sqrt(c11* c11 + c12* c12) = 1 2.A) Rows will be perpendicular to each other (r11 , r12 ) . ( r21 , r22) = 0 B) Columns will be perpendicular to each other (c11 , c12 ) . (c21 ,c22) = 0 e.g. Rotation matrix is orthogonal            100 0cossin 0sincos   • Orthogonal Transformation  Rigid-Body Transformation • For any orthogonal matrix B  B-1 = BT
  • 24.
    Concatenation properties.  Matrixmultiplication : associative • ex) For three matrices A, B and C • Translation or Rotation : additive property commutative • scaling : multiplicative property commutative  However, Translation and Rotation : non commutative • order of transformation matrix multiplication is important A B C (A B) C A (B C)        ABBA 
  • 26.
    26 Commutative of TransformationMatrices • In general matrix multiplication is not commutative • For the following special cases commutativity holds i.e. M1.M2 = M2.M1 M1 M2 Translate Translate Scale Scale Rotate Rotate Uniform Scale Rotate • Some non-commutative Compositions:  Non-uniform scale, Rotate  Translate, Scale  Rotate, Translate Original Transitional Final
  • 27.
    Composite Transformation (1/2) Translation  If two successive translation factor (tx1, ty1) and (tx2, ty2) are applied to a coordinate point P • then • ex) i.e,  Two successive Translation are additive 1 0 t 0 1 t 0 0 1 1 0 t 0 1 t 0 0 1 1 0 t t 0 1 t t 0 0 1 x2 y2 x1 y1 x1 x2 y1 y2                                   P' T (t ,t ) {T (t ,t ) P} {T (t ,t ) T (t ,t )} P2 X2 y2 1 x1 y1 2 X2 y2 1 x1 y1      T(t ,t ) T(t ,t ) T(t t ,t t )x2 y2 x1 y1 x1 x2 y1 y2   
  • 28.
    Composite Transformation (2/2) Rotation  two successive rotation  two successive rotations are also additive  Scaling  successive scalings are multiplicative P)}R(){R(P}){R()R(P 1212   )R()R()R( 2121   P' R( ) P1 2      ,                                  100 0ss0 00ss 100 0s0 00s 100 0s0 00s y2y1 x2x1 y1 x1 y2 x2 S(S ,S ) S(S ,S ) S(S S ,S S )X2 Y2 X1 Y1 X1 X2 Y1 Y2   
  • 29.
    General pivot-point Rotation(1/2)  Rotation about arbitrary point p (xr, yr)  step1) Translate P to origin  step2) Rotation about origin  step3) Retranslation to position P.
  • 30.
    General pivot-point Rotation(2/2)  Composite transformation matrix                         x y x y x y y x r r r r r r r r                                                 cos sin sin cos cos sin ( cos ) sin sin cos ( cos ) sin             ),y,R(x),-yT(-x)R()y,T(x rrrrrr  
  • 31.
  • 32.
    General Fixed-Point Scaling Scaling about arbitrary point p(xr, yr)  step 1) translate p to origin  step 2) scaling about origin  step 3) Retranslate to position P                             x y s s x y s x s s y s r r x y r r x r x y r y                                              ( ) ( ) )ss,y,S(x),-yT(-x)sS(s)y,T(x yxffffyxff ,, 
  • 33.
    Other Transformations :Reflection (1/3)  Reflection : produce a mirror images of an object  We need axis of reflection  rotating the objects 180°about reflection axis
  • 34.
     Reflection aboutthe x axis: Just flip the y coordinate  Reflection about the y axis: Just flip the x coordinate  Reflection about the origin, flip both coordinates 1 32 1 32 1 32 1’ 3’2’ 1’ 2’3’ 1’ 2’3’ Reflection about x axis Reflection about y axis Reflection about origin Reflection (2/3) R 1 0 0 0 1 0 0 0 1 y            R 1 0 0 0 1 0 0 0 1 X                          100 010 001 R0
  • 35.
    Reflection (3/3)  Reflectionthrough arbitrary point P (xr, yr) • translate point p to origin : Tr • perform reflection about origin : Ro • retranslate to original position : Tr  Reflection through y=x line                                   100 y10 x01 100 010 001 100 y10 x01 r r r r 0 1 0 1 0 0 0 0 1          
  • 37.
    Reflection through anarbitrary line y=Lx+b
  • 38.
    Shear Transformation  Shear: distorts the shape of an object  Shear transformation that distorts the shape of an object such that the transformed shape appears as if the object were composed of internal layers that had been caused to slide over each other.  Shearing (slide over) can be in either x or y direction  In X Shear, x-values changes along x-direction by shearing factor of shx • point is shifted by horizontally by an amount proportional to its distance from x-axis • y values are unchanged  In Y Shear, y-values changes along y-direction by shearing factor of shy • point is shifted by vertically by an amount proportional to its distance from y-axis • x values are unchanged
  • 39.
  • 40.
    Transformation matrix ofX- Shear • So, • Transformed positions T 1 sh 0 0 1 0 0 0 1 shx x            x' x sh yx   , y' y
  • 41.
    X –Shear relativeto y- reference line
  • 42.
    Transformation matrix ofX- Shear with y- reference line  X-direction shearing relative to liney yref 1 sh sh y 0 1 0 0 0 1 x x ref          yy' )y(yshxx' refx  
  • 43.
  • 44.
    Y – Shearrelative to x reference line  y-direction shearing relative to linex xref 1 0 0 sh 1 sh x 0 0 1 y y ref           x' x y' y sh (x x )y ref    
  • 46.
     The areaof the parallelogram can be calculated as,  Area of the trapezium =(sum of two parallel side)*h / 2  Parea = (a+c) (b+d) – (ab) – (cd) – (b+b+d) – (c+a+c) = ad – bc = det  Thus, area of any parallelogram is formed by transforming a square which is a function of the transformation matrix determinant and is related to the area of the initial square Parea = Sarea (ad-bc) = Sarea det [T]  Area of any transformed figure Tarea is related to the ar ea of the initial figure Iarea by, Tarea = Iarea (ad-bc) 2 1 2 1 2 c 2 b       dc ba
  • 47.
    WINDOW TO VIEWPORT TRANSFORMATION
  • 51.
    ASSIGNMENT -2 TWO–D TRANSFORMATION Assigned Date : 26-02-13 Submission Date : 05-03-13  Fo r a l l t h e b e l o w g i v e n pr o b l e m Or i g i n a l a n d Fi n a l po s i t i o n d i a g r a m i s n e c e s s a r y 1. Scale a square at [(2, 2), (6, 6)] along one of its diagonal and find the new vertices. 2. Perform a clockwise 30 degree rotation of a triangle A (2, 3), B (5, 5), C(4,3) about the point (1,1) 3. Find a transformation of triangle A (1, 0), B (0, 1), C (1, 1) by a) Rotating 30 degree about the origin and then translating one unit in x and y direction. b) Translating one unit in x and y direction and then rotating 30 degree about the origin. 4. Represent a triangle at [(3, 3), (5, 6) , (7,3) ] in a new coordinate system with origin at (3,3) and its x-axis making an angle +45 degree with the x-direction of the base coordinate system. 5. Find out the co-ordinate of a figure bounded by (0,0) , (1,5) , (6,3) (- 3,-4) when reflected along the line whose equation is y=1 (x+5) and sheared by 2 units in x –direction and 2 units in y-direction. [HINT: Ref -Page No. 3-46 in Godse Book] 6. Compute the new reflected coordinates of a point (-4,-4), when reflected with respect to a line that passes through (-4, 0) and (0,-4) [HINT: Ref -Page No. 3-62 in Godse Book] 7. For a point (2, 4) in a window at [(1, 1), (5, 5)], find the equivalent point in the View Port at [(1, 1), (5, 10)].