Post on 01-Feb-2016
description
Graphics
Graphics Lab @ Korea University
cgvr.korea.ac.kr
2D Geometric Transformations
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Contents
Definition & Motivation 2D Geometric Transformation
Translation Rotation Scaling
Matrix Representation Homogeneous Coordinates Matrix Composition Composite Transformations
Pivot-Point Rotation General Fixed-Point Scaling Reflection and Shearing Transformations Between Coordinate Systems
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Geometric Transformation
Definition Translation, Rotation, Scaling
Motivation – Why do we need geometric
transformations in CG? As a viewing aid As a modeling tool As an image manipulation tool
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Scaling
ModelingCoordinates
World Coordinates
Scale(0.3, 0.3)
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Rotation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)
World Coordinates
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Translation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)Translate(5, 3)
World Coordinates
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
Again?
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
ScaleTranslate
ScaleRotate
Translate
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
Transformationscan be combined
(with simple algebra)
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
syy
sxxx
y
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
)cossy)(ysinsx)((xy
)sinsy)(ycossx)((xx
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
ty)cossy)(ysinsx)((xy
tx)sinsy)(ycossx)((xx
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
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
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Matrix Composition
Rotate by around arbitrary point (a,b)
Scale by sx, sy around arbitrary point (a,b)
T(-a,-b))R(b)T(a,M θ
T(-a,-b)sy)S(sx,b)T(a,M
(a,b)
(a,b)
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Pivot-Point Rotation
100
sin)cos1(cossin
sin)cos1(sincos
100
10
01
100
0cossin
0sincos
100
10
01
rr
rr
r
r
r
r
xy
yx
y
x
y
x
,,,, rrrrrr yxRyxTRyxT
Translate Rotate Translate
(xr,yr
)(xr,yr
)(xr,yr
)(xr,yr
)
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
General Fixed-Point Scaling
100
)1(0
)1(0
100
10
01
100
00
00
100
10
01
yfy
xfx
f
fx
f
f
sys
sxs
y
x
s
s
y
x
y
Translate Scale Translate
(xf,yf
)(xf,yf
)(xf,yf
)(xf,yf
)
yxffffyxff ssyxSyxTssSyxT ,,,, ,,
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Reflection
Reflection with respect to the axis • x • y • xy
100
010
001
100
010
001
100
010
001
x
y 1
32
1’
3’2’x
y1
32
1’
3’ 2
x
y
3
1’
3’ 2
1
2
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Reflection with respect to a Line
Clockwise rotation of 45 Reflection about the x axis Counterclockwise rotation of 45
Reflection
100
001
010
y=x
x
y 1
32
1’
3’
2’
x
y
x
y
x
y
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Shear
Converted to a parallelogram
x’ = x + shx · y, y’ = y
Transformed to a shifted parallelogram(Y = Yref)
x’ = x + shx · (y-yref), y’ = y
100
010
01 xsh
100
010
1 refxx yshsh
(Shx=2)
(Shx=1/2, yref=-1)
x
y
x
y
x
y
x
y
(0,0) (1,0)
(1,1)(0,1)
(0,0) (1,0)
(1,1)(0,1)
(0,0) (1,0)
(3,1)(2,1)
(1/2,0)(3/2,0)
(2,1)(1,1)
(0,-1)
CGVR
Graphics Lab @ Korea University
cgvr.korea.ac.kr
Shear
Transformed to a shifted parallelogram(X = Xref)
x’ = x, y’ = shy · (x-xref) + y
100
1
001
refyy xshsh
(Shy=1/2, xref=-1)
x
y
x
y
(-1,0)(0,0) (1,0)
(1,1)(0,1)(0,1/2) (1,1)
(1,2)(0,3/2)