Transcript 슬라이드 1
Graphics
2D Geometric
Transformations
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Contents
CGVR
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
Graphics Lab @ Korea University
Geometric Transformation
Definition
CGVR
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
Graphics Lab @ Korea University
Example: 2D Geometric
Transformation
CGVR
Modeling
Coordinates
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Example: 2D Scaling
CGVR
Modeling
Coordinates
Scale(0.3, 0.3)
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Example: 2D Rotation
CGVR
Modeling
Coordinates
Scale(0.3, 0.3)
Rotate(-90)
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Example: 2D Translation
CGVR
Modeling
Coordinates
Scale(0.3, 0.3)
Rotate(-90)
Translate(5, 3)
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Example: 2D Geometric
Transformation
CGVR
Modeling
Coordinates
Again?
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Example: 2D Geometric
Transformation
Modeling
Coordinates
CGVR
Scale
Translate
Scale
Rotate
Translate
World Coordinates
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
x x hx y
y y hy x
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
Transformations
can be combined
(with simple algebra)
x x hx y
y y hy x
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
x x hx y
y y hy x
cgvr.korea.ac.kr
x x sx
y y sy
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
x x hx y
y y hy x
cgvr.korea.ac.kr
x ((x sx) cos (y sy) sin )
y ((x sx) sin (y sy) cos )
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
x x hx y
y y hy x
cgvr.korea.ac.kr
x ((x sx) cos (y sy) sin ) tx
y ((x sx) sin (y sy) cos ) ty
Graphics Lab @ Korea University
Basic 2D Transformations
Translation
x x sx
y y sy
Rotation
x x tx
y y ty
Scale
CGVR
x x cosθ - y sinθ
y y sinθ y cosθ
Shear
x x hx y
y y hy x
cgvr.korea.ac.kr
x ((x sx) cos (y sy) sin ) tx
y ((x sx) sin (y sy) cos ) ty
Graphics Lab @ Korea University
Matrix Representation
CGVR
Represent a 2D Transformation by a Matrix
a b
c d
Apply the Transformation to a Point
x ax by
y cx dy
x a b x
y c d y
Transformation
Matrix
cgvr.korea.ac.kr
Point
Graphics Lab @ Korea University
Matrix Representation
CGVR
Transformations can be combined by matrix
multiplication
x a b e f i j x
y c d g h k l y
Transformation
Matrix
Matrices are a convenient and efficient way
to represent a sequence of transformations
cgvr.korea.ac.kr
Graphics Lab @ Korea University
2×2 Matrices
CGVR
What types of transformations can be
represented with a 2×2 matrix?
2D Identity
x x
y y
x 1 0 x
y 0 1 y
2D Scaling
x sx x
y sy y
cgvr.korea.ac.kr
x sx 0 x
y 0 sy y
Graphics Lab @ Korea University
2×2 Matrices
CGVR
What types of transformations can be
represented with a 2×2 matrix?
2D Rotation
x cos x sin y
y sin x cos y
x cos sin x
y sin cos y
2D Shearing
x x shx y
y shy x y
x 1 shx x
y shy 1 y
cgvr.korea.ac.kr
Graphics Lab @ Korea University
2×2 Matrices
CGVR
What types of transformations can be
represented with a 2×2 matrix?
2D Mirror over Y axis
x x
x 1 0 x
y
y y
y
0
1
2D Mirror over (0,0)
x x
x 1 0 x
y
y y
y
0
1
cgvr.korea.ac.kr
Graphics Lab @ Korea University
2×2 Matrices
CGVR
What types of transformations can be
represented with a 2×2 matrix?
2D Translation
x x tx
y y ty
NO!!
Only linear 2D transformations
can be Represented with 2x2 matrix
cgvr.korea.ac.kr
Graphics Lab @ Korea University
2D Translation
CGVR
2D translation can be represented by a 3×3
matrix
Point represented with homogeneous coordinates
x x tx
y y ty
cgvr.korea.ac.kr
x 1 0 tx x
y 0 1 ty y
1 0 0 1 1
Graphics Lab @ Korea University
Basic 2D Transformations
CGVR
Basic 2D transformations as 3x3 Matrices
x 1 0 tx x
y 0 1 ty y
1 0 0 1 1
x sx 0 0 x
y 0 sy 0 y
1 0 0 1 1
Translate
Scale
x cos sin 0 x
y sin cos
y
0
1 0
0
1 1
x 1 shx 0 x
y shy 1 0 y
1 0 0 1 1
Rotate
Shear
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Homogeneous Coordinates
CGVR
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
y
2
(2, 1, 1) or (4, 2, 2) or (6, 3, 3)
1
1 2
x
Convenient Coordinate System to
Represent Many Useful Transformations
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Matrix Composition
CGVR
Transformations can be combined by matrix
multiplication
x 1 0 tx cosθ - sinθ 0 sx 0 0 x
y 0 1 ty sinθ cosθ 0 0 sy 0 y
w 0 0 1 0
0
1 0 0 1 w
p
T (tx,ty)
R( )
S(sx, sy)
p
Efficiency with premultiplication
Matrix multiplication is associative
p (T (R (S p)))
cgvr.korea.ac.kr
p (T R S) p
Graphics Lab @ Korea University
Matrix Composition
CGVR
Rotate by around arbitrary point (a,b)
M T(a, b) R(θ ) T(-a,-b)
(a,b)
Scale by sx, sy around arbitrary point (a,b)
M T(a, b) S(sx, sy) T(-a,-b)
(a,b)
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Pivot-Point Rotation
(xr,yr)
Translate
(xr,yr)
Rotate
CGVR
(xr,yr)
(xr,yr)
Translate
T xr , yr R T xr , yr Rxr , yr ,
1 0 x r cos sin 0 1 0 x r cos sin x r (1 cos ) y r sin
0 1 y sin cos 0 0 1 y sin cos y (1 cos ) x sin
r
r
r
r
0 0 1 0
0
1 0 0 1 0
0
1
cgvr.korea.ac.kr
Graphics Lab @ Korea University
General Fixed-Point Scaling
(xf,yf)
(xf,yf)
Scale
Translate
CGVR
(xf,yf)
(xf,yf)
Translate
T x f , y f S sx , sy T x f , y f S x f , y f , sx , sy
1 0
0 1
0 0
x f s x
y f 0
1 0
cgvr.korea.ac.kr
0
sy
0
0 1 0
0 0 1
1 0 0
x f s x
y f 0
1 0
0
sy
0
x f (1 s x )
y f (1 s y )
1
Graphics Lab @ Korea University
Reflection
CGVR
Reflection with respect to the axis
•
•
x
1 0 0
0 1 0
0 0 1
1 0 0
0 1 0
0 0 1
y
1
cgvr.korea.ac.kr
1
2
3
2’
3’
1’
•
y
2
x
y
3
xy
1 0 0
0 1 0
0
0 1
y
1’
3’
3’
2
x
1’
3
1
2
x
2
Graphics Lab @ Korea University
Reflection
CGVR
Reflection with respect to a Line
y
0 1 0
1 0 0
0 0 1
x
y=x
Clockwise rotation of 45 Reflection about the x
axis Counterclockwise rotation of 45
y
y
x
1
y
2
3
2’
3’
x
x
1’
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Shear
CGVR
Converted to a parallelogram
1 sh x 0
0 1 0
0 0 1
x’ = x + shx · y, y’ = y
y
(0,1)
(1,1)
(0,0)
(1,0)
y
(2,1)
x
(0,0)
(1,0)
(3,1)
x
(Shx=2)
Transformed to a shifted parallelogram
(Y = Yref)
1 sh x
0 1
0 0
sh x y ref
0
1
x’ = x + shx · (y-yref),
cgvr.korea.ac.kr
y’ = y
y
(0,1)
y
(1,1)
(2,1)
(1,1)
(1/2,0)
(0,0)
(1,0)
x
(3/2,0) x
(0,-1)
(Shx=1/2, yref=-1)
Graphics Lab @ Korea University
Shear
CGVR
Transformed to a shifted parallelogram
(X = Xref)
1
sh
y
0
x’ = x,
0
0
1 sh y x ref
0
1
y
(0,1)
(1,1)
(0,0)
(1,0)
(0,3/2)
(1,2)
(0,1/2)
(1,1)
y
x
(-1,0)
x
y’ = shy · (x-xref) + y
(Shy=1/2, xref=-1)
cgvr.korea.ac.kr
Graphics Lab @ Korea University