graphics graphics lab @ korea university cgvr.korea.ac.kr 2d geometric transformations...
TRANSCRIPT
Graphics
cgvr.korea.ac.kr Graphics Lab @ Korea University
2D Geometric Transformations
고려대학교 컴퓨터 그래픽스 연구실
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Scaling
ModelingCoordinates
World Coordinates
Scale(0.3, 0.3)
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Rotation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)
World Coordinates
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Translation
ModelingCoordinates
Scale(0.3, 0.3)Rotate(-90)Translate(5, 3)
World Coordinates
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
Again?
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Example: 2D Geometric Transformation
ModelingCoordinates
World Coordinates
ScaleTranslate
ScaleRotate
Translate
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
Scale
Rotation
Shear
txxx tyyy
sxxx syyy
sinθy-cosθxx cosθysinθyy
yhxxx xhyyy
syy
sxxx
y
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
)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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
Reflection
Reflection with respect to the axis • x 축에 대한 반사 • y 축에 대한 반사 • xy 축
( 원점 ) 에 대한
100
010
001
100
010
001
100
010
001
y 축에 대한 반사x 축에 대한 반사 원점에 대한 반사
x
y 1
32
1’
3’2’x
y1
32
1’
3’ 2
x
y
3
1’
3’ 2
1
2
cgvr.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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.korea.ac.kr
CGVR
Graphics Lab @ Korea University
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)