Download - Hearn and Baker 2 D transformations
2D Geometric Transformations
Taher S. Vijay Computer Academy
August 2011
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
Taher S. - VCA- 2011
Example: 2D Scaling
ModelingCoordinates
World Coordinates
Scale(0.3, 0.3)
Taher S. - VCA- 2011
Example: 2D Rotation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)
World Coordinates
Taher S. - VCA- 2011
Example: 2D Translation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)Translate(5, 3)
World Coordinates
Taher S. - VCA- 2011
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
Again?
Taher S. - VCA- 2011
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
ScaleTranslate
ScaleRotate
Translate
Taher S. - VCA- 2011
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
Taher S. - VCA- 2011
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)
Taher S. - VCA- 2011
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
syy
sxxx
y
Taher S. - VCA- 2011
)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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
2×2 Matrices
What types of transformations can be represented with a 2×2 matrix?
2D Translation
txxx tyyy
y
x
ty
tx
y
x
0
0
Careful!
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
Linear Transformations
Linear transformations are combinations of … Scale Rotation Shear, and Mirror
Properties of linear transformations Satisfies: Origin maps to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition
)()()( 22112211 pTspTspspsT
w
y
x
dc
ba
w
y
x
100
0
0
Taher S. - VCA- 2011
Affine Transformations
Affine transformations are combinations of Linear transformations, and Translations
Properties of affine transformations Origin does not map to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition
w
y
x
fed
cba
w
y
x
100
Taher S. - VCA- 2011
Projective Transformations
Projective transformations… Affine transformations, and Projective warps
Properties of projective transformations Origin does not map to origin Lines map to lines Parallel lines do not necessarily remain parallel Ratios are not preserved Closed under composition
w
y
x
ihg
fed
cba
w
y
x
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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)
Taher S. - VCA- 2011
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
)
Taher S. - VCA- 2011
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 ,,,, ,,
Taher S. - VCA- 2011
Reflection
Reflection with respect to the axis • x • y • xy
100
010
001
100
010
001
100
010
001
yx
x
y 1
32
1’
3’2’x
y1
32
1’
3’ 2
x
y
3
1’
3’ 2
1
2
xy
Taher S. - VCA- 2011
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
Taher S. - VCA- 2011
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
x (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)
Taher S. - VCA- 2011
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)