SlideShare a Scribd company logo
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…

More Related Content

What's hot

Two dimensionaltransformations
Two dimensionaltransformationsTwo dimensionaltransformations
Two dimensionaltransformations
Nareek
 
Clipping
ClippingClipping
Clipping
AMIT VIRAMGAMI
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algoMohd Arif
 
Sharpening spatial filters
Sharpening spatial filtersSharpening spatial filters
Linear models for classification
Linear models for classificationLinear models for classification
Linear models for classification
Sung Yub Kim
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
Ummiya Mohammedi
 
Computer Graphics - clipping
Computer Graphics - clippingComputer Graphics - clipping
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Tweening and morphing
Tweening and morphingTweening and morphing
Tweening and morphingAmit Kapoor
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
Timbal Mayank
 
Composite transformation
Composite transformationComposite transformation
Composite transformation
Pooja Dixit
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
RobinAhmedSaikat
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
Rajani Thite
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
Ankit Surti
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
Maruf Abdullah (Rion)
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewingMohd Arif
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligence
sandeep54552
 
Back face detection
Back face detectionBack face detection
Back face detection
Pooja Dixit
 

What's hot (20)

Two dimensionaltransformations
Two dimensionaltransformationsTwo dimensionaltransformations
Two dimensionaltransformations
 
Clipping
ClippingClipping
Clipping
 
Midpoint circle algo
Midpoint circle algoMidpoint circle algo
Midpoint circle algo
 
Sharpening spatial filters
Sharpening spatial filtersSharpening spatial filters
Sharpening spatial filters
 
Linear models for classification
Linear models for classificationLinear models for classification
Linear models for classification
 
Depth Buffer Method
Depth Buffer MethodDepth Buffer Method
Depth Buffer Method
 
Computer Graphics - clipping
Computer Graphics - clippingComputer Graphics - clipping
Computer Graphics - clipping
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Clipping
ClippingClipping
Clipping
 
Tweening and morphing
Tweening and morphingTweening and morphing
Tweening and morphing
 
2D transformation (Computer Graphics)
2D transformation (Computer Graphics)2D transformation (Computer Graphics)
2D transformation (Computer Graphics)
 
Composite transformation
Composite transformationComposite transformation
Composite transformation
 
Shading
ShadingShading
Shading
 
03.Scan Conversion.ppt
03.Scan Conversion.ppt03.Scan Conversion.ppt
03.Scan Conversion.ppt
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"COMPUTER GRAPHICS-"Projection"
COMPUTER GRAPHICS-"Projection"
 
Cohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping AlgorithmCohen-Sutherland Line Clipping Algorithm
Cohen-Sutherland Line Clipping Algorithm
 
Two dimensional viewing
Two dimensional viewingTwo dimensional viewing
Two dimensional viewing
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligence
 
Back face detection
Back face detectionBack face detection
Back face detection
 

Similar to Transformations in Computer Graphics

Part 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptxPart 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptx
Khalil Alhatab
 
Geometric transformation cg
Geometric transformation cgGeometric transformation cg
Geometric transformation cgharinipriya1994
 
Part 2- Transformation.pptx
Part 2- Transformation.pptxPart 2- Transformation.pptx
Part 2- Transformation.pptx
Khalil Alhatab
 
Part 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptxPart 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptx
Khalil Alhatab
 
04transformation2d
04transformation2d04transformation2d
04transformation2dKetan Jani
 
Computer Vision transformations
Computer Vision  transformationsComputer Vision  transformations
Computer Vision transformations
Wael Badawy
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
lifebreath
 
affine transformation for computer graphics
affine transformation for computer graphicsaffine transformation for computer graphics
affine transformation for computer graphics
DrSUGANYADEVIK
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
Debjit Doira
 
06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
RobinAhmedSaikat
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
Bala Murali
 
lec07_transformations.pptx
lec07_transformations.pptxlec07_transformations.pptx
lec07_transformations.pptx
AneesAbbasi14
 
2d transformations
2d transformations2d transformations
2d transformations
rajeshranjithsingh
 
2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinatesTarun Gehlot
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
sandeep kumbhkar
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
Daffodil International University
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
Amol Gaikwad
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
aravindangc
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
Patel Punit
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
SIMONTHOMAS S
 

Similar to Transformations in Computer Graphics (20)

Part 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptxPart 3- Manipulation and Representation of Curves.pptx
Part 3- Manipulation and Representation of Curves.pptx
 
Geometric transformation cg
Geometric transformation cgGeometric transformation cg
Geometric transformation cg
 
Part 2- Transformation.pptx
Part 2- Transformation.pptxPart 2- Transformation.pptx
Part 2- Transformation.pptx
 
Part 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptxPart 2- Geometric Transformation.pptx
Part 2- Geometric Transformation.pptx
 
04transformation2d
04transformation2d04transformation2d
04transformation2d
 
Computer Vision transformations
Computer Vision  transformationsComputer Vision  transformations
Computer Vision transformations
 
Lecture 9-online
Lecture 9-onlineLecture 9-online
Lecture 9-online
 
affine transformation for computer graphics
affine transformation for computer graphicsaffine transformation for computer graphics
affine transformation for computer graphics
 
GeometricTransformations.ppt
GeometricTransformations.pptGeometricTransformations.ppt
GeometricTransformations.ppt
 
06.Transformation.ppt
06.Transformation.ppt06.Transformation.ppt
06.Transformation.ppt
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
lec07_transformations.pptx
lec07_transformations.pptxlec07_transformations.pptx
lec07_transformations.pptx
 
2d transformations
2d transformations2d transformations
2d transformations
 
2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates2 d transformations and homogeneous coordinates
2 d transformations and homogeneous coordinates
 
Transforms UNIt 2
Transforms UNIt 2 Transforms UNIt 2
Transforms UNIt 2
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
Unit-3 overview of transformations
Unit-3 overview of transformationsUnit-3 overview of transformations
Unit-3 overview of transformations
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Two dimentional transform
Two dimentional transformTwo dimentional transform
Two dimentional transform
 
Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2Cs8092 computer graphics and multimedia unit 2
Cs8092 computer graphics and multimedia unit 2
 

Transformations in Computer Graphics

  • 2. 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. 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 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
  • 6. 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. 7 2D Rotation about the origin. y x r r P’(x’,y’) P(x,y) 
  • 8. 8 2D Rotation about the origin. y x r r P’(x’,y’) P(x,y)   y   sin. cos. ry rx   x
  • 9. 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. 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. 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  
  • 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  
  • 14. Example: 2D Scaling Modeling Coordinates World Coordinates Scale(0.3, 0.3)
  • 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
  • 18. Example: 2D Geometric Transformation Modeling Coordinates World Coordinates 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 • 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
  • 26. 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
  • 27. 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
  • 28. 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  
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. 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
  • 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 we perform 2 translations on the same point 34 ),(),(),( :expectweSo ),(),(),( ),( ),( 21212211 21212211 22 11 yyxxyxyx yyxxyxyx yx yx ddddTddTddT PddddTPddTddTP PddTP PddTP    
  • 36. 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
  • 38. 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 :
  • 39. 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
  • 40. Homogeneous form of rotation. 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 of rotation. 42 carefulmorebetoneed,rotations3DFor sametheis rotationofaxisthebecauseonlyisBut this )()()()( and )()()( )0(   RRRR RRR IR   
  • 43. 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
  • 44. 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)
  • 45. 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
  • 46. 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))
  • 47. 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
  • 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. • 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
  • 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 the x-axis Rx() 53                                                11000 0θcosθsin0 0θsinθcos0 0001 1 z y x z y x
  • 54. Rotating About the y-axis Ry() 54                                                11000 0θcos0θsin 0010 0θsin0θcos 1 z y x z y x
  • 55. Rotation About the z-axis Rz() 55                                               11000 0100 00θcosθsin 00θsinθcos 1 z y x z y x
  • 56. Rotation • Not commutative if the axis of rotation are not parallel )()()()(  xyyx RRRR 
  • 57. 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
  • 58. 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
  • 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