Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object...
-
Upload
silas-fitzgerald -
Category
Documents
-
view
213 -
download
0
Transcript of Lecture Notes: Computer Graphics. Why Transformations? In graphics, once we have an object...
Lecture Notes:
Computer Graphics
Why Transformations?
• In graphics, once we have an object described, transformations are used to move that object, scale it and rotate it
Transformation
• Two complementary views– Geometric trans: Object is transformed relative to a stationary
coordinate system
– Coordinate trans: Object is held stationary while the coordinate system is transformed
• Ex: moving an automobile against a scenic background– Move the auto and keep the background fixed (GT)
– Keep the car fixed and move the background (CT)
Basic 2D Geometric Transformations
• Four basic types– Translation
– Scaling
– Rotation
– Shear (possible using a combination of rotation and scaling)
Translation
• Simply moves an object from one position to another
xnew = xold + tx ynew = yold + ty
Note: House shifts position relative to origin
y
x 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
Scaling
• Scalar multiplies all coordinates
• WATCH OUT: Objects grow and move!
xnew = Sx × xold ynew = Sy × yold
Note: House shifts position relative to origin
y
x 0
1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
1
2
1
3
3
6
3
9
Rotation
• Rotates all coordinates by a specified angle
xnew = xold × cosθ – yold × sinθ
ynew = xold × sinθ + yold × cosθ
• Points are always rotated about the origin
6
y
x 0 1
1
2
2
3 4 5 6 7 8 9 10
3
4
5
6
Shear
• Along X-axis
• Along Y-axis
yhxxx s
xhyyy s
Basic 2D Geometric Transformations
• Translation– –
• Scale– –
• Rotation– –
• Shear
– –
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθxy
yhxxx sxhyyy s
Transformation and Matrix Multiplication
• Recall how matrix multiplication takes place:
ziyhxg
zfyexd
zcybxa
z
y
x
ihg
fed
cba
***
***
***
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
TransformationMatrix 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
TransformationMatrix
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 transformationscan be Represented with 2x2 matrix
Homogeneous Coordinates
• A point (x, y) can be re-written in homogeneous coordinates as (xh, yh, h)
• The homogeneous parameter h is a non-zero value such that:
• We can then write any point (x, y) as (hx, hy, h)
• We can conveniently choose h = 1 so that (x, y) becomes (x, y, 1)
h
xx h
h
yy h
Homogeneous Coordinates
• Add a 3rd coordinate to every 2D point– (x, y, w) represents a point at location (x/w, y/w)
– (x, y, 0) represents a point at infinity
– (0, 0, 0) is not allowed
1 2
1
2
x
y
(2, 1, 1) or (4, 2, 2) or (6, 3, 3)
Convenient Coordinate System to
Represent Many Useful Transformations
Why Homogeneous Coordinates?
• Mathematicians commonly use homogeneous coordinates as they allow scaling factors to be removed from equations
• We will see in a moment that all of the transformations we discussed previously can be represented as 3*3 matrices
• Using homogeneous coordinates allows us use matrix multiplication to calculate transformations – extremely efficient!
Homogeneous Translation
•The translation of a point by (dx, dy) can be written in matrix form as:
• Representing the point as a homogeneous column vector we perform the calculation as:
100
10
01
dy
dx
11*1*0*0
1**1*0
1**0*1
1100
10
01
dyy
dxx
yx
dyyx
dxyx
y
x
dy
dx
Homogenous Coordinates
• To make operations easier, 2-D points are written as homogenous coordinate column vectors
vdydxTvdyy
dxx
y
x
dy
dx
),(':
11100
10
01
vssSvys
xs
y
x
s
s
yxy
x
y
x
),(':
11100
00
00
Translation:
Scaling:
Basic 2D Transformations
• Basic 2D transformations as 3x3 Matrices
1100
10
01
1
y
x
ty
tx
y
x
1100
0cossin
0sincos
1
y
x
y
x
1100
00
00
1
y
x
sy
sx
y
x
1100
01
01
1
y
x
shy
shx
y
x
Translate
Shear
Scale
Rotate
Combining Transformations
•A number of transformations can be combined into one matrix to make things easy
– Allowed by the fact that we use homogenous coordinates
• Imagine rotating a polygon around a point other than the origin
– Transform to centre point to origin
– Rotate around origin
– Transform back to centre point
Matrix Composition
• Transformations can be combined by matrix multiplication
• Efficiency with premultiplication
– Matrix multiplication is associative
w
y
x
1 0 0
0sy0
00sx
1 0 0
0cosθinθ
0 sinθ- θcos
100
10
01
sty
tx
w
y
x
p ty)T(tx, )R( sy)S(sx, p
p)))S(R(T(p pS)RT(p
Combining Transformations (cont…))(HHouse HdydxT ),(
HdydxTR ),()( HdydxTRdydxT ),()(),(
1 2
3 4
Combining Transformations (cont…)
• The three transformation matrices are combined as follows
1100
10
01
100
0cossin
0sincos
100
10
01
y
x
dy
dx
dy
dx
REMEMBER: Matrix multiplication is not commutative so order matters
vdydxTRdydxTv ),()(),('
Matrix Composition
• Rotate by around arbitrary point (a,b)
–
• Scale by sx, sy around arbitrary point (a,b)
–
a,-b-TRba,TM θ
a,-b-Tsysx,Sba,TM
(a,b)
(a,b)
Inverse Transformations
•Transformations can easily be reversed using inverse transformations
100
10
011 ty
tx
T
100
01
0
001
1
y
x
s
s
S
100
0cossin
0sincos1
R
Basic 2D Coordinate Transformations
• Translation
–
–
• Scale
–
–
• Rotation
–
–
• Shear ??
txxx tyyy
sx)/1(xx
sy)/1(yy
sinθycosθxx cosθysinθxy