Computer Graphics
1
Topic:
Transformations
Name: Jatender Khatri
2
Transformations.
What is a transformation?
• P=T(P)
What does it do?
Transform the coordinates / normal vectors of objects
Why use them?
• Modelling
-Moving the objects to the desired location in the environment
-Multiple instances of a prototype shape
-Kinematics of linkages/skeletons – character animation
• Viewing
– Virtual camera: parallel and perspective projections
3
Types of Transformations
– Geometric Transformations
• Translation
• Rotation
• scaling
• Linear (preserves parallel lines)
• Non-uniform scales, shears or skews
– Projection (preserves lines)
• Perspective projection
• Parallel projection
– Non-linear (lines become curves)
• Twists, bends, warps, morphs,
12/12/2019 Lecture 1 4
Geometric Transformation
– Once the models are prepared, we need to place them in
the environment
– Objects are defined in their own local coordinate
system
– We need to translate, rotate and scale them to put them
into the world coordinate system
5
2D Translations.
TPP
d
d
T
y
x
P
y
x
P
dyydxx
yxP
yxPP
yx
























Now
,,
torscolumn vectheDefine
axis.ytoparalleldaxis,xtoparallelddistancea),(Pointtotranslate
),,(asdefinedPoint
y
x
yx
P
P’
6
2D Scaling from the origin.






























y
x
.
0
0
y
x
or
Now
0
0
matrixtheDefine
.,.
axis.ythealongsand
axis,xthealongsfactoraby),(Pointto(stretch)scaleaPerform
),,(asdefinedPoint
y
x
y
x
y
x
yx
s
s
PSP
s
s
S
ysyxsx
yxP
yxPP
P
P’
7
2D Rotation about the origin.
y
x
r
r
P’(x’,y’)
P(x,y)

8
2D Rotation about the origin.
y
x
r
r
P’(x’,y’)
P(x,y)


y


sin.
cos.
ry
rx


x
9
2D Rotation about the origin.
y
x
r
r
P’(x’,y’)
P(x,y)


y


sin.
cos.
ry
rx


x


co.sin.sin.cos.)sin(.
sin.sin.cos.cos.)cos(.
rrry
rrrx


10
2D Rotation about the origin.


sin.
cos.
ry
rx




cos.sin.sin.cos.)sin(.
sin.sin.cos.cos.)cos(.
rrry
rrrx


Substituting for r :
Gives us :


cos.sin.
sin.cos.
yxy
yxx


11
2D Rotation about the origin.


cos.sin.
sin.cos.
yxy
yxx


Rewriting in matrix form gives us :











 








y
x
y
x
.
cossin
sincos


PRPR 




 
 ,
cossin
sincos
matrixtheDefine


Transformations.
• Translation.
– P=T + P
• Scale
– P=S  P
• Rotation
– P=R  P
• We would like all transformations to be multiplications so
we can concatenate them
•  express points in homogenous coordinates.
12











 








y
x
y
x
.
cossin
sincos


Example: 2D Geometric
Transformation
Modeling
Coordinates
World Coordinates
Example: 2D Scaling
Modeling
Coordinates
World Coordinates
Scale(0.3, 0.3)
Example: 2D Rotation
Modeling
Coordinates
Scale(0.3, 0.3)
Rotate(-90)
World Coordinates
Example: 2D Translation
Modeling
Coordinates
Scale(0.3, 0.3)
Rotate(-90)
Translate(5, 3)
World Coordinates
Example: 2D Geometric
Transformation
Modeling
Coordinates
World Coordinates
Again?
Example: 2D Geometric
Transformation
Modeling
Coordinates
World Coordinates
Scale
Translate
Scale
Rotate
Translate
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
Transformations
can be combined
(with simple algebra)
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
syy
sxxx


y
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
)cossy)(ysinsx)((xy
)sinsy)(ycossx)((xx




txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
ty)cossy)(ysinsx)((xy
tx)sinsy)(ycossx)((xx




txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
Basic 2D Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear
–
–
txxx 
tyyy 
sxxx 
syyy 
sinθy-cosθxx 
cosθysinθyy 
yhxxx 
xhyyy 
ty)cossy)(ysinsx)((xy
tx)sinsy)(ycossx)((xx




Matrix Representation
• Represent a 2D Transformation by a Matrix
• Apply the Transformation to a Point




















y
x
dc
ba
y
x
dycxy
byaxx








dc
ba
Transformation
Matrix
Point
Matrix Representation
• Transformations can be combined by matrix
multiplication
































y
x
lk
ji
hg
fe
dc
ba
y
x
Matrices are a convenient and efficient way
to represent a sequence of transformations
Transformation
Matrix
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Identity
2D Scaling
yy
xx


ysyy
xsxx






















y
x
y
x
10
01




















y
x
sy
sx
y
x
0
0
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Rotation
2D Shearing











 








y
x
y
x


cossin
sincos




















y
x
shy
shx
y
x
1
1
yxy
yxx




cossin
sincos
yxshyy
yshxxx


2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Mirror over Y axis
2D Mirror over (0,0)
yy
xx


yy
xx






















y
x
y
x
10
01






















y
x
y
x
10
01
2×2 Matrices
• What types of transformations can be
represented with a 2×2 matrix?
2D Translation
txxx 
tyyy  NO!!
Only linear 2D transformations
can be Represented with 2x2 matrix
2D Translation
• 2D translation can be represented by a 3×3
matrix
– Point represented with homogeneous coordinates
txxx 
tyyy 

































1100
10
01
1
y
x
ty
tx
y
x
Homogeneous coordinates
• Add an extra coordinate, W, to a point.
– P(x,y,W).
• Two sets of homogeneous coordinates represent the
same point if they are a multiple of each other.
– (2,5,3) and (4,10,6) represent the same point.
• If W 0 , divide by it to get Cartesian coordinates of point
(x/W,y/W,1).
• If W=0, point is said to be at infinity.
32
Translations in homogenised
coordinates
• Transformation matrices for 2D translation
are now 3x3.
33

































1
.
100
10
01
1
y
x
d
d
y
x
y
x
11


y
x
dyy
dxx
Concatenation.
• When we perform 2 translations on the same point
34
),(),(),(
:expectweSo
),(),(),(
),(
),(
21212211
21212211
22
11
yyxxyxyx
yyxxyxyx
yx
yx
ddddTddTddT
PddddTPddTddTP
PddTP
PddTP




Concatenation.
35
?
100
10
01
.
100
10
01
:is),(),(productmatrixThe
2
2
1
1
2211






















y
x
y
x
yxyx
d
d
d
d
ddTddT
Matrix product is variously referred to as compounding,
concatenation, or composition
Concatenation.
36
Matrix product is variously referred to as compounding, concatenation, or
composition.


































100
10
01
100
10
01
.
100
10
01
:is),(),(productmatrixThe
21
21
2
2
1
1
2211
yy
xx
y
x
y
x
yxyx
dd
dd
d
d
d
d
ddTddT
Properties of translations.
37
),(),(T4.
),(),(),(),(3.
),(),(),(2.
)0,0(1.
1-
yxyx
yxyxyxyx
yyxxyxyx
ssTss
ssTttTttTssT
tstsTttTssT
IT




Note : 3. translation matrices are commutative.
Homogeneous form of scale.
38







y
x
yx
s
s
ssS
0
0
),(
Recall the (x,y) form of Scale :











100
00
00
),( y
x
yx s
s
ssS
In homogeneous coordinates :
Concatenation of scales.
39
!multeasy to-matrixin theelementsdiagonalOnly
100
0ss0
00ss
100
0s0
00s
.
100
0s0
00s
:is),(),(productmatrixThe
y2y1
x2x1
y2
x2
y1
x1
2211

































 yxyx ssSssS
Homogeneous form of rotation.
40



















 













1
.
100
0cossin
0sincos
1
y
x
y
x


)()(
:i.e,orthogonalarematricesRotation
).()(
matrices,rotationFor
1
1


T
RR
RR




Orthogonality of rotation
matrices.
41




















 

100
0cossin
0sincos
)(,
100
0cossin
0sincos
)( 



 T
RR
























100
0cossin
0sincos
100
0cossin
0sincos
)( 



R
Other properties of rotation.
42
carefulmorebetoneed,rotations3DFor
sametheis
rotationofaxisthebecauseonlyisBut this
)()()()(
and
)()()(
)0(


RRRR
RRR
IR



How are transforms combined?
02/10/09 Lecture 4 43
(0,0)
(1,1)
(2,2)
(0,0)
(5,3)
(3,1)
Scale(2,2) Translate(3,1)
TS =
2
0
0
2
0
0
1
0
0
1
3
1
2
0
0
2
3
1=
Scale then Translate
Use matrix multiplication: p' = T ( S p ) = TS p
Caution: matrix multiplication is NOT commutative!
0 0 1 0 0 1 0 0 1
Non-commutative Composition
02/10/09 Lecture 4 44
Scale then Translate: p' = T ( S p ) = TS p
Translate then Scale: p' = S ( T p ) = ST p
(0,0)
(1,1)
(4,2)
(3,1)
(8,4)
(6,2)
(0,0)
(1,1)
(2,2)
(0,0)
(5,3)
(3,1)
Scale(2,2) Translate(3,1)
Translate(3,1) Scale(2,2)
Non-commutative Composition
02/10/09 Lecture 4 45
TS =
2
0
0
0
2
0
0
0
1
1
0
0
0
1
0
3
1
1
ST =
2
0
0
2
0
0
1
0
0
1
3
1
Scale then Translate: p' = T ( S p ) = TS p
2
0
0
0
2
0
3
1
1
2
0
0
2
6
2
=
=
Translate then Scale: p' = S ( T p ) = ST p
0 0 1 0 0 1 0 0 1
How are transforms combined?
02/10/09 Lecture 4 46
(0,0)
(1,1)
(0,sqrt(2))
(0,0)
(3,sqrt(2))
(3,0)
Rotate 45 deg Translate(3,0)
Rotate then Translate
Caution: matrix multiplication is NOT commutative!
Translate then Rotate
(0,0)
(1,1)
(0,0) (3,0)
Rotate 45 deg
Translate(3,0) (3/sqrt(2),3/sqrt(2))
Non-commutative Composition
02/10/09 Lecture 4 47
TR =
0
1
0
-1
0
0
0
0
1
1
0
0
0
1
0
3
1
1
RT =
1
0
0
1
3
1
Rotate then Translate: p' = T ( R p ) = TR p
0
0
0
-1
0
0
3
1
1
0
1
0
-1
0
0
-1
3
1
=
=
Translate then Rotate: p' = R ( T p ) = RT p
0 0 1
0
1
0
-1
0
0
0
0
1
0
1
0
-1
0
0
0
0
1
0
1
0
-1
0
0
0
0
1
0
1
0
-1
0
0
0
0
1
0
1
0
-1
0
0
0
0
1
Types of transformations.
• Rotation and translation
– Angles and distances are preserved
– Unit cube is always unit cube
– Rigid-Body transformations.
• Rotation, translation and scale.
– Angles & distances not preserved.
– But parallel lines are.
48
3D Transformations.
• Use homogeneous coordinates, just as in 2D case.
• Transformations are now 4x4 matrices.
• We will use a right-handed (world) coordinate
system - ( z out of page ).
Lecture 4 49
Translation in 3D.
50













1000
100
010
001
),,(
z
y
x
zyx
d
d
d
dddT
Simple extension to the 3D case:
Scale in 3D.
51













1000
000
000
000
),,(
z
y
x
zyx
s
s
s
sssS
Simple extension to the 3D case:
Rotation in 3D
• Need to specify which axis the rotation is about.
• z-axis rotation is the same as the 2D case.
52











 

1000
0100
00cossin
00sincos
)(


zR
Rotating About the x-axis Rx()
53















































11000
0θcosθsin0
0θsinθcos0
0001
1
z
y
x
z
y
x
Rotating About the y-axis
Ry()
54















































11000
0θcos0θsin
0010
0θsin0θcos
1
z
y
x
z
y
x
Rotation About the z-axis
Rz()
55














































11000
0100
00θcosθsin
00θsinθcos
1
z
y
x
z
y
x
Rotation
• Not commutative if the axis of rotation are
not parallel
)()()()(  xyyx RRRR 
Calculating the world
coordinates of all vertices
• For each object, there is a local-to-global
transformation matrix
• So we apply the transformations to all the
vertices of each object
• We now know the world coordinates of all
the points in the scene
57
Normal Vectors
58
• We also need to know the direction of the normal
vectors in the world coordinate system
• This is going to be used at the shading operation
• We only want to rotate the normal vector
• Do not want to translate it
Normal Vectors - (2)
59
• We need to set elements of the translation
part to zero

























1000
0
0
0
1000
111111
111111
111111
111111
111111
111111
rrr
rrr
rrr
trrr
trrr
trrr
z
y
x
Summary.
• Transformations: translation, rotation and scaling
• Using homogeneous transformation, 2D (3D)
transformations can be represented by multiplication of a
3x3 (4x4) matrix.
• Multiplication from left-to-right can be considered as the
transformation of the coordinate system
60
That’s All!
Thank You
For Listening…

Transformations in Computer Graphics

  • 1.
  • 2.
    2 Transformations. What is atransformation? • P=T(P) What does it do? Transform the coordinates / normal vectors of objects Why use them? • Modelling -Moving the objects to the desired location in the environment -Multiple instances of a prototype shape -Kinematics of linkages/skeletons – character animation • Viewing – Virtual camera: parallel and perspective projections
  • 3.
    3 Types of Transformations –Geometric Transformations • Translation • Rotation • scaling • Linear (preserves parallel lines) • Non-uniform scales, shears or skews – Projection (preserves lines) • Perspective projection • Parallel projection – Non-linear (lines become curves) • Twists, bends, warps, morphs,
  • 4.
    12/12/2019 Lecture 14 Geometric Transformation – Once the models are prepared, we need to place them in the environment – Objects are defined in their own local coordinate system – We need to translate, rotate and scale them to put them into the world coordinate system
  • 5.
  • 6.
    6 2D Scaling fromthe origin.                               y x . 0 0 y x or Now 0 0 matrixtheDefine .,. axis.ythealongsand axis,xthealongsfactoraby),(Pointto(stretch)scaleaPerform ),,(asdefinedPoint y x y x y x yx s s PSP s s S ysyxsx yxP yxPP P P’
  • 7.
    7 2D Rotation aboutthe origin. y x r r P’(x’,y’) P(x,y) 
  • 8.
    8 2D Rotation aboutthe origin. y x r r P’(x’,y’) P(x,y)   y   sin. cos. ry rx   x
  • 9.
    9 2D Rotation aboutthe origin. y x r r P’(x’,y’) P(x,y)   y   sin. cos. ry rx   x   co.sin.sin.cos.)sin(. sin.sin.cos.cos.)cos(. rrry rrrx  
  • 10.
    10 2D Rotation aboutthe origin.   sin. cos. ry rx     cos.sin.sin.cos.)sin(. sin.sin.cos.cos.)cos(. rrry rrrx   Substituting for r : Gives us :   cos.sin. sin.cos. yxy yxx  
  • 11.
    11 2D Rotation aboutthe origin.   cos.sin. sin.cos. yxy yxx   Rewriting in matrix form gives us :                      y x y x . cossin sincos   PRPR         , cossin sincos matrixtheDefine  
  • 12.
    Transformations. • Translation. – P=T+ P • Scale – P=S  P • Rotation – P=R  P • We would like all transformations to be multiplications so we can concatenate them •  express points in homogenous coordinates. 12                      y x y x . cossin sincos  
  • 13.
  • 14.
  • 15.
    Example: 2D Rotation Modeling Coordinates Scale(0.3,0.3) Rotate(-90) World Coordinates
  • 16.
    Example: 2D Translation Modeling Coordinates Scale(0.3,0.3) Rotate(-90) Translate(5, 3) World Coordinates
  • 17.
  • 18.
    Example: 2D Geometric Transformation Modeling Coordinates WorldCoordinates Scale Translate Scale Rotate Translate
  • 19.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy 
  • 20.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy  Transformations can be combined (with simple algebra)
  • 21.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy  syy sxxx   y
  • 22.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – )cossy)(ysinsx)((xy )sinsy)(ycossx)((xx     txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy 
  • 23.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – ty)cossy)(ysinsx)((xy tx)sinsy)(ycossx)((xx     txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy 
  • 24.
    Basic 2D Transformations •Translation – – • Scale – – • Rotation – – • Shear – – txxx  tyyy  sxxx  syyy  sinθy-cosθxx  cosθysinθyy  yhxxx  xhyyy  ty)cossy)(ysinsx)((xy tx)sinsy)(ycossx)((xx    
  • 25.
    Matrix Representation • Representa 2D Transformation by a Matrix • Apply the Transformation to a Point                     y x dc ba y x dycxy byaxx         dc ba Transformation Matrix Point
  • 26.
    Matrix Representation • Transformationscan be combined by matrix multiplication                                 y x lk ji hg fe dc ba y x Matrices are a convenient and efficient way to represent a sequence of transformations Transformation Matrix
  • 27.
    2×2 Matrices • Whattypes of transformations can be represented with a 2×2 matrix? 2D Identity 2D Scaling yy xx   ysyy xsxx                       y x y x 10 01                     y x sy sx y x 0 0
  • 28.
    2×2 Matrices • Whattypes of transformations can be represented with a 2×2 matrix? 2D Rotation 2D Shearing                      y x y x   cossin sincos                     y x shy shx y x 1 1 yxy yxx     cossin sincos yxshyy yshxxx  
  • 29.
    2×2 Matrices • Whattypes of transformations can be represented with a 2×2 matrix? 2D Mirror over Y axis 2D Mirror over (0,0) yy xx   yy xx                       y x y x 10 01                       y x y x 10 01
  • 30.
    2×2 Matrices • Whattypes of transformations can be represented with a 2×2 matrix? 2D Translation txxx  tyyy  NO!! Only linear 2D transformations can be Represented with 2x2 matrix
  • 31.
    2D Translation • 2Dtranslation can be represented by a 3×3 matrix – Point represented with homogeneous coordinates txxx  tyyy                                   1100 10 01 1 y x ty tx y x
  • 32.
    Homogeneous coordinates • Addan extra coordinate, W, to a point. – P(x,y,W). • Two sets of homogeneous coordinates represent the same point if they are a multiple of each other. – (2,5,3) and (4,10,6) represent the same point. • If W 0 , divide by it to get Cartesian coordinates of point (x/W,y/W,1). • If W=0, point is said to be at infinity. 32
  • 33.
    Translations in homogenised coordinates •Transformation matrices for 2D translation are now 3x3. 33                                  1 . 100 10 01 1 y x d d y x y x 11   y x dyy dxx
  • 34.
    Concatenation. • When weperform 2 translations on the same point 34 ),(),(),( :expectweSo ),(),(),( ),( ),( 21212211 21212211 22 11 yyxxyxyx yyxxyxyx yx yx ddddTddTddT PddddTPddTddTP PddTP PddTP    
  • 35.
  • 36.
    Concatenation. 36 Matrix product isvariously referred to as compounding, concatenation, or composition.                                   100 10 01 100 10 01 . 100 10 01 :is),(),(productmatrixThe 21 21 2 2 1 1 2211 yy xx y x y x yxyx dd dd d d d d ddTddT
  • 37.
  • 38.
    Homogeneous form ofscale. 38        y x yx s s ssS 0 0 ),( Recall the (x,y) form of Scale :            100 00 00 ),( y x yx s s ssS In homogeneous coordinates :
  • 39.
    Concatenation of scales. 39 !multeasyto-matrixin theelementsdiagonalOnly 100 0ss0 00ss 100 0s0 00s . 100 0s0 00s :is),(),(productmatrixThe y2y1 x2x1 y2 x2 y1 x1 2211                                   yxyx ssSssS
  • 40.
    Homogeneous form ofrotation. 40                                   1 . 100 0cossin 0sincos 1 y x y x   )()( :i.e,orthogonalarematricesRotation ).()( matrices,rotationFor 1 1   T RR RR    
  • 41.
    Orthogonality of rotation matrices. 41                       100 0cossin 0sincos )(, 100 0cossin 0sincos )(      T RR                         100 0cossin 0sincos 100 0cossin 0sincos )(     R
  • 42.
    Other properties ofrotation. 42 carefulmorebetoneed,rotations3DFor sametheis rotationofaxisthebecauseonlyisBut this )()()()( and )()()( )0(   RRRR RRR IR   
  • 43.
    How are transformscombined? 02/10/09 Lecture 4 43 (0,0) (1,1) (2,2) (0,0) (5,3) (3,1) Scale(2,2) Translate(3,1) TS = 2 0 0 2 0 0 1 0 0 1 3 1 2 0 0 2 3 1= Scale then Translate Use matrix multiplication: p' = T ( S p ) = TS p Caution: matrix multiplication is NOT commutative! 0 0 1 0 0 1 0 0 1
  • 44.
    Non-commutative Composition 02/10/09 Lecture4 44 Scale then Translate: p' = T ( S p ) = TS p Translate then Scale: p' = S ( T p ) = ST p (0,0) (1,1) (4,2) (3,1) (8,4) (6,2) (0,0) (1,1) (2,2) (0,0) (5,3) (3,1) Scale(2,2) Translate(3,1) Translate(3,1) Scale(2,2)
  • 45.
    Non-commutative Composition 02/10/09 Lecture4 45 TS = 2 0 0 0 2 0 0 0 1 1 0 0 0 1 0 3 1 1 ST = 2 0 0 2 0 0 1 0 0 1 3 1 Scale then Translate: p' = T ( S p ) = TS p 2 0 0 0 2 0 3 1 1 2 0 0 2 6 2 = = Translate then Scale: p' = S ( T p ) = ST p 0 0 1 0 0 1 0 0 1
  • 46.
    How are transformscombined? 02/10/09 Lecture 4 46 (0,0) (1,1) (0,sqrt(2)) (0,0) (3,sqrt(2)) (3,0) Rotate 45 deg Translate(3,0) Rotate then Translate Caution: matrix multiplication is NOT commutative! Translate then Rotate (0,0) (1,1) (0,0) (3,0) Rotate 45 deg Translate(3,0) (3/sqrt(2),3/sqrt(2))
  • 47.
    Non-commutative Composition 02/10/09 Lecture4 47 TR = 0 1 0 -1 0 0 0 0 1 1 0 0 0 1 0 3 1 1 RT = 1 0 0 1 3 1 Rotate then Translate: p' = T ( R p ) = TR p 0 0 0 -1 0 0 3 1 1 0 1 0 -1 0 0 -1 3 1 = = Translate then Rotate: p' = R ( T p ) = RT p 0 0 1 0 1 0 -1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1 0 1 0 -1 0 0 0 0 1
  • 48.
    Types of transformations. •Rotation and translation – Angles and distances are preserved – Unit cube is always unit cube – Rigid-Body transformations. • Rotation, translation and scale. – Angles & distances not preserved. – But parallel lines are. 48
  • 49.
    3D Transformations. • Usehomogeneous coordinates, just as in 2D case. • Transformations are now 4x4 matrices. • We will use a right-handed (world) coordinate system - ( z out of page ). Lecture 4 49
  • 50.
  • 51.
  • 52.
    Rotation in 3D •Need to specify which axis the rotation is about. • z-axis rotation is the same as the 2D case. 52               1000 0100 00cossin 00sincos )(   zR
  • 53.
    Rotating About thex-axis Rx() 53                                                11000 0θcosθsin0 0θsinθcos0 0001 1 z y x z y x
  • 54.
    Rotating About they-axis Ry() 54                                                11000 0θcos0θsin 0010 0θsin0θcos 1 z y x z y x
  • 55.
    Rotation About thez-axis Rz() 55                                               11000 0100 00θcosθsin 00θsinθcos 1 z y x z y x
  • 56.
    Rotation • Not commutativeif the axis of rotation are not parallel )()()()(  xyyx RRRR 
  • 57.
    Calculating the world coordinatesof all vertices • For each object, there is a local-to-global transformation matrix • So we apply the transformations to all the vertices of each object • We now know the world coordinates of all the points in the scene 57
  • 58.
    Normal Vectors 58 • Wealso need to know the direction of the normal vectors in the world coordinate system • This is going to be used at the shading operation • We only want to rotate the normal vector • Do not want to translate it
  • 59.
    Normal Vectors -(2) 59 • We need to set elements of the translation part to zero                          1000 0 0 0 1000 111111 111111 111111 111111 111111 111111 rrr rrr rrr trrr trrr trrr z y x
  • 60.
    Summary. • Transformations: translation,rotation and scaling • Using homogeneous transformation, 2D (3D) transformations can be represented by multiplication of a 3x3 (4x4) matrix. • Multiplication from left-to-right can be considered as the transformation of the coordinate system 60
  • 61.