Post on 18-Jan-2018
description
II-1
Transformations• Transformations are needed to:
– Position objects defined relative to the origin– Build scenes based on hierarchies– Project objects from three to two dimensions
• Transformations include:– Translation– Scaling– Rotation– Reflections
• Transformations can be represented by matrices and matrix multiplication
II 2D Transformation
II-2
• Transformation of Points
yx
yx
• Representation of Points: ;
**)()( yxdybxcyaxdcba
yxTX
• Transformation of Straight Lines
II-3
Rotation• Consider rotation about the origin by
degrees– radius stays the same, angle increases by
x’=x cos –y sin y’ = x sin + y cos
x = r cos y = r sin
x’ = r cos (y’ = r sin (
II-4
• The transformation for a general rotation about the origin by an arbitrary angle
cossinsincos
T
cossinsincos
*** yxyxTXX
cossinsincos
T
yx
yx
XTX
cossinsincos
***
II-5
Scaling• Scaling increases or decreases the size of the
object• Scaling occurs with respect to the origin
– If the object is not centered at the origin, it will move in addition to changing size
• In general, this is done with the equations:xn = sx * xyn = sy * y
• This can also be done with the matrix multiplication:
yx
ss
yx
y
x
n
n
00
II-6
2002
T
2/1003
T• Example:
II-7
Reflection• corresponds to negative scale factors
originalsx = -1 sy = 1
sx = -1 sy = -1 sx = 1 sy = -1
II-8
10
01T
1001
T
0110
T
0110
T
• The reflection about the y=x is obtained by
• The reflection about the y-axis (x=0) is obtained by
• The reflection about the x-axis (y=0) is obtained by
• The reflection about the y=-x is obtained by
II-9
II-10
II-11
Translations• The amount of the translation is added to or
subtracted from the x and y coordinates• In general, this is done with the equations:
xn = x + tx
yn = y + ty
• This can also be done with the matrix multiplication:
11001001
1yx
tt
yx
y
x
n
n
1010001
11
yx
nn
ttyxyx
II-12
Homogeneous Coordinates• The two dimensional point (x, y) is represented by
the homogeneous coordinate (x, y, 1)• Some transformations will alter this third
component so it is no longer 1• In general, the homogeneous coordinate (x, y, w)
represents the two dimensional point (x/w, y/w)• General transformation matrix:
100
nmdcba
T
100ndcmba
T
II-13
Order of Transformations• Matrix multiplication is not commutative so
changing the order of transformation can change the result
• For example, changing the order of a translation and a rotation produces a different result:
II-14
II-15
II-16
II-17
• Rotation about an arbitrary point through an angle
nm
1010001
1000cossin0sincos
1010001
11**
nmnmyxyx
II-18
II-19
II-20