Graphics
2D Geometric Transformations
cgvr.korea.ac.kr
Graphics Lab @ Korea University
Contents
Definition & Motivation 2D Geometric Transformation
CGVR
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 Graphics Lab @ Korea University
Geometric Transformation
CGVR
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
Graphics Lab @ Korea University
Example: 2D Geometric Transformation
CGVR
Modeling Coordinates
World Coordinates Graphics Lab @ Korea University
Example: 2D Scaling
CGVR
Modeling Coordinates
Scale(0.3, 0.3)
World Coordinates Graphics Lab @ Korea University
Example: 2D Rotation
CGVR
Modeling Coordinates
Scale(0.3, 0.3) Rotate(-90) World Coordinates Graphics Lab @ Korea University
Example: 2D Translation
CGVR
Modeling Coordinates
Scale(0.3, 0.3) Rotate(-90) Translate(5, 3) World Coordinates Graphics Lab @ Korea University
Example: 2D Geometric Transformation
CGVR
Modeling Coordinates Again?
World Coordinates Graphics Lab @ Korea University
Example: 2D Geometric Transformation Modeling Coordinates
CGVR
Scale Translate
Scale Rotate Translate World Coordinates 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 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 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
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
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
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
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
Point Graphics Lab @ Korea University
Matrix Representation
CGVR
Transformations can be combined by matrix multiplication
x ′ a b e y ′ = c d g
f i j x h k l y
Transformation Matrix Matrices are a convenient and efficient way to represent a sequence of transformations 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
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
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
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
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
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 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 Graphics Lab @ Korea University
Linear Transformations
CGVR
Linear transformations are combinations of … Scale x′ a b 0 x Rotation y ′ = c d 0 y Shear, and w′ 0 0 1 w Mirror Properties of linear transformations Satisfies: T ( s p + s p ) = s T ( p ) + s T ( p ) 1 1 2 2 1 1 2 2
Origin maps to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition
Graphics Lab @ Korea University
Affine Transformations
Affine transformations are combinations of
CGVR
Linear transformations, and Translations x′ a b
c x y′ = d e f y w′ 0 0 1 w Properties of affine transformations
Origin does not map to origin Lines map to lines Parallel lines remain parallel Ratios are preserved Closed under composition
Graphics Lab @ Korea University
Projective Transformations
Projective transformations…
CGVR
Affine transformations, and Projective warps x′ a
b c x y′ = d e f y w′ g h i w 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
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)))
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)
Graphics Lab @ Korea University
Pivot-Point Rotation
(xr,yr)
Translate
(xr,yr)
CGVR
(xr,yr)
Rotate
(xr,yr)
Translate
T ( xr , y r ) ⋅ R ( θ ) ⋅ T ( − x r , − y r ) = R ( xr , y r , θ ) 1 0 x r cos θ − sin θ 0 1 0 − x r cos θ − sin θ 0 1 y ⋅ sin θ cos θ 0 ⋅ 0 1 − y = sin θ cos θ r r 0 0 1 0 0 1 0 0 1 0 0
x r (1 − cos θ ) + y r sin θ y r (1 − cos θ ) − x r sin θ 1 Graphics Lab @ Korea University
General Fixed-Point Scaling
(xf,yf)
(xf,yf)
Translate
Scale
CGVR
(xf,yf)
(xf,yf)
Translate
T ( x f , y f ) ⋅ S ( s x , s y ) ⋅ T ( − x f ,− y f ) = S ( x f , y f , s x , s y ) 1 0 0 1 0 0
s x ⋅0 1 0
xf yf
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
1
2
3
2’
3’
2
y
3
x
y
1’ 3’
xy
(
)
− 1 0 0 0 − 1 0 0 0 1
2 x
1’ 3’
3
1
2 x
2
1’
x
•
y
y 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’ Graphics Lab @ Korea University
Shear
CGVR
Converted to a parallelogram 1 sh x 0 1 0 0
x’ = x + shx · y,
0 0 1
y (0,1)
(1,1)
(0,0)
(1,0)
y (2,1) x
(1,0)
x
y’ = y
x
(0,0)
(3,1)
(Shx=2)
Transformed to a shifted parallelogram (Y = Yref) 1 sh x 0 1 0 0 x’ = x + shx · (y-yref),
− sh x ⋅ y ref 0 1 y’ = y
y (0,1)
(1,1)
(0,0)
(1,0)
y
x
(1,1) (1/2,0)
(2,1) (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)
Graphics Lab @ Korea University