lect6 transformation2d
DESCRIPTION
created by Sudipta mandalTRANSCRIPT
BCETContents
n Definition & Motivationn 2D Geometric Transformation
n Translationn Rotationn Scaling
n Matrix Representationn Homogeneous Coordinatesn Matrix Compositionn Composite Transformations
n Pivot-Point Rotationn General Fixed-Point Scalingn Reflection and Shearingn Transformations Between Coordinate Systems
BCETGeometric Transformation
n Definitionn Translation, Rotation, Scaling.
n Motivation – Why do we need geometrictransformations in CG?n As a viewing aidn As a modeling tooln As an image manipulation tool
BCET
Example: 2D GeometricTransformation
ModelingCoordinates
World Coordinates
BCETExample: 2D Scaling
ModelingCoordinates
World Coordinates
Scale(0.3, 0.3)
BCETExample: 2D Rotation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)
World Coordinates
BCETExample: 2D Translation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)Translate(5, 3)
World Coordinates
BCET
Example: 2D GeometricTransformation
ModelingCoordinates
World Coordinates
Again?
BCET
Example: 2D GeometricTransformation
ModelingCoordinates
World Coordinates
ScaleTranslate
ScaleRotate
Translate
BCETBasic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
BCETBasic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
Transformationscan be combined
(with simple algebra)
BCETBasic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
syysxxx
´=¢´=¢
y
BCET
)cossy)(ysinsx)((xy)sinsy)(ycossx)((xx
qqqq
´´+´´=¢´´-´´=¢
Basic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
BCET
ty)cossy)(ysinsx)((xytx)sinsy)(ycossx)((xx
+´´+´´=¢+´´-´´=¢
qqqq
Basic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
BCETBasic 2D Transformations
n Translationn
n
n Scalen
n
n Rotationn
n
n Shearn
n
txxx +=¢tyyy +=¢
sxxx ´=¢syyy ´=¢
sinθy-cosθxx ´´=¢cosθysinθyy ´+´=¢
yhxxx ´+=¢xhyyy ´+=¢
ty)cossy)(ysinsx)((xytx)sinsy)(ycossx)((xx
+´´+´´=¢+´´-´´=¢
qqqq
BCETMatrix Representation
n Represent a 2D Transformation by a Matrix
n Apply the Transformation to a Point
úû
ùêë
éúû
ùêë
é=ú
û
ùêë
颢
yx
dcba
yx
dycxybyaxx
+=¢+=¢
úû
ùêë
édcba
TransformationMatrix Point
BCETMatrix Representation
n Transformations can be combined by matrixmultiplication
úû
ùêë
éúû
ùêë
éúû
ùêë
éúû
ùêë
é=ú
û
ùêë
颢
yx
lkji
hgfe
dcba
yx
Matrices are a convenient and efficient wayto represent a sequence of transformations
TransformationMatrix
BCET2×2 Matrices
n What types of transformations can berepresented with a 2×2 matrix?2D Identity
2D Scalingyyxx
=¢=¢
ysyyxsxx
´=¢´=¢
úû
ùêë
éúû
ùêë
é=ú
û
ùêë
颢
yx
yx
1001
úû
ùêë
éúû
ùêë
é=ú
û
ùêë
颢
yx
sysx
yx
00
BCET2×2 Matrices
n What types of transformations can berepresented with a 2×2 matrix?2D Rotation
2D Shearing
úû
ùêë
éúû
ùêë
é -=ú
û
ùêë
颢
yx
yx
qqqq
cossinsincos
úû
ùêë
éúû
ùêë
é=ú
û
ùêë
颢
yx
shyshx
yx
11
yxyyxx
´+´=¢´-´=¢
qqqq
cossinsincos
yxshyyyshxxx
+´=¢´+=¢
BCET2×2 Matrices
n What types of transformations can berepresented with a 2×2 matrix?2D Mirror over Y axis
2D Mirror over (0,0)yyxx
=¢-=¢
yyxx
-=¢-=¢
úû
ùêë
éúû
ùêë
é-=ú
û
ùêë
颢
yx
yx
1001
úû
ùêë
éúû
ùêë
é-
-=ú
û
ùêë
颢
yx
yx
1001
BCET2×2 Matrices
n What types of transformations can berepresented with a 2×2 matrix?2D Translation
txxx +=¢tyyy +=¢ NO!!
Only linear 2D transformationscan be Represented with 2x2 matrix
BCETHomogeneous Coordinates
nA point (x, y) can be re-written in homogeneouscoordinates as (xh, yh, h).nThe homogeneous parameter h is a non-zero value such that:
nWe can then write any point (x, y) as (hx, hy, h)nWe can conveniently choose h = 1 so that(x, y) becomes (x, y, 1)
hxx h=
hyy h=
BCET
Why HomogeneousCoordinates?
nMathematicians commonly use homogeneouscoordinates as they allow scaling factors to beremoved from equations.nWe will see in a moment that all of thetransformations we discussed previously can berepresented as 3*3 matrices.nUsing homogeneous coordinates allows us usematrix multiplication to calculate transformations –extremely efficient!
BCETHomogeneous Translation
nThe translation of a point by (dx, dy) can bewritten in matrix form as:
nRepresenting the point as a homogeneouscolumn vector we perform the calculation as:
úúú
û
ù
êêê
ë
é
1001001
dydx
úúú
û
ù
êêê
ë
é++
=úúú
û
ù
êêê
ë
é
++++++
=úúú
û
ù
êêê
ë
é´úúú
û
ù
êêê
ë
é
11*1*0*01**1*01**0*1
11001001
dyydxx
yxdyyxdxyx
yx
dydx
BCET2D Translation
n 2D translation can be represented by a 3×3matrixn Point represented with homogeneous coordinates
txxx +=¢tyyy +=¢
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
颢
11001001
1yx
tytx
yx
BCETBasic 2D Transformations
n Basic 2D transformations as 3x3 Matrices
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
颢
11001001
1yx
tytx
yx
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é -=
úúú
û
ù
êêê
ë
颢
11000cossin0sincos
1yx
yx
qqqq
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
颢
11000000
1yx
sysx
yx
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
颢
11000101
1yx
shyshx
yx
Translate
Shear
Scale
Rotate
BCETHomogeneous Coordinates
n Add a 3rd coordinate to every 2D pointn (x, y, w) represents a point at location (x/w, y/w)n (x, y, 0) represents a point at infinityn (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 toRepresent Many Useful Transformations
BCETLinear Transformations
n Linear transformations are combinations of …n Scalen Rotationn Shear, andn Mirror
n Properties of linear transformationsn Satisfies:n Origin maps to originn Lines map to linesn Parallel lines remain paralleln Ratios are preservedn Closed under composition
)()()( 22112211 pTspTspspsT +=+
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
é
¢¢¢
wyx
dcba
wyx
10000
BCETAffine Transformations
n Affine transformations are combinations ofn Linear transformations, andn Translations
n Properties of affine transformationsn Origin does not map to originn Lines map to linesn Parallel lines remain paralleln Ratios are preservedn Closed under composition
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
é
¢¢¢
wyx
fedcba
wyx
100
BCETMatrix Composition
n Transformations can be combined by matrixmultiplication
n Efficiency with premultiplicationn Matrix multiplication is associative
úúú
û
ù
êêê
ë
é
÷÷÷
ø
ö
ççç
è
æ
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é
úúú
û
ù
êêê
ë
é=
úúú
û
ù
êêê
ë
é
¢¢¢
wyx
1000sy000sx
1000cosθinθ0sinθ-θcos
1001001
stytx
wyx
=¢p ty)T(tx, )R(q sy)S(sx, p
p)))S(R(T(p ´´´=¢ pS)RT(p ´´´=¢
BCETMatrix Composition
n Rotate by q around arbitrary point (a,b)n
n Scale by sx, sy around arbitrary point (a,b)n
T(-a,-b))R(b)T(a,M ´´= θ
T(-a,-b)sy)S(sx,b)T(a,M ´´=
(a,b)
(a,b)
BCETInverse Transformations
nTransformations can easily be reversed usinginverse transformations
úúú
û
ù
êêê
ë
é--
=-
1001001
1 dydx
T
úúúúúú
û
ù
êêêêêê
ë
é
=-
100
010
001
1
y
x
s
s
S
úúú
û
ù
êêê
ë
é-=-
1000cossin0sincos
1 qqqq
R
BCETPivot-Point Rotation
úúú
û
ù
êêê
ë
é--+--
=úúú
û
ù
êêê
ë
é--
×úúú
û
ù
êêê
ë
é -×úúú
û
ù
êêê
ë
é
100sin)cos1(cossinsin)cos1(sincos
1001001
1000cossin0sincos
1001001
qqqqqqqq
qqqq
rr
rr
r
r
r
r
xyyx
yx
yx
( ) ( ) ( ) ( )qq ,,,, rrrrrr yxRyxTRyxT =--××
Translate Rotate Translate
(xr,yr) (xr,yr) (xr,yr)(xr,yr)
BCETGeneral Fixed-Point Scaling
úúú
û
ù
êêê
ë
é--
=úúú
û
ù
êêê
ë
é--
×úúú
û
ù
êêê
ë
é×
úúú
û
ù
êêê
ë
é
100)1(0)1(0
1001001
1000000
1001001
yfy
xfx
f
fx
f
f
syssxs
yx
ss
yx
y
Translate Scale Translate
(xf,yf) (xf,yf) (xf,yf) (xf,yf)
( ) ( ) ( ) ( )yxffffyxff ssyxSyxTssSyxT ,,,, ,, =--××
BCETReflection
n Reflection with respect to the axis• x • y • xy
úúú
û
ù
êêê
ë
é-
100010001
úúú
û
ù
êêê
ë
é-
100010001
úúú
û
ù
êêê
ë
é-
-
100010001
Y AXISX AXIS XY AXIS
x
y 1
32
1’
3’2’x
y1
32
1’
3’ 2
x
y
3
1’
3’ 2
1
2
BCET
n Reflection with respect to a Line
n Clockwise rotation of 45 ® Reflection about the xaxis ® Counterclockwise rotation of 45
Reflection
úúú
û
ù
êêê
ë
é
100001010
y=x
x
y 1
32
1’
3’2’x
y
x
y
x
y
°
°
BCETShear
n Converted to a parallelogram
x’ = x + shx · y, y’ = y
n Transformed to a shifted parallelogram(Y = Yref)
x’ = x + shx · (y-yref), y’ = y
úúú
û
ù
êêê
ë
é
10001001 xsh
úúú
û
ù
êêê
ë
é ×-
100010
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)
BCETShear
n Transformed to a shifted parallelogram(X = Xref)
x’ = x, y’ = shy · (x-xref) + y
úúú
û
ù
êêê
ë
é×-
1001
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)