2D Transformations: CMPT 361 Introduction To Computer Graphics Torsten Möller
2D Transformations: CMPT 361 Introduction To Computer Graphics Torsten Möller
CMPT 361
Introduction to Computer Graphics
Torsten Möller
© Machiraju/Zhang/Möller
Graphics Pipeline
Hardware
Modelling Transform Visibility
Illumination +
Shading
Perception, Texture/
Color Realism
Interaction
© Machiraju/Zhang/Möller 2
Reading
• Chapter 4 of Angel
• Chapter 5 of Foley, van Dam, …
© Machiraju/Zhang/Möller 3
Schedule
• Geometry basics
• Affine transformations
• Use of homogeneous coordinates
• Concatenation of transformations
• 3D transformations
• Transformation of coordinate systems
• Transform the transforms
• Transformations in OpenGL
© Machiraju/Zhang/Möller 4
Basic transformations
• The most basic ones
– Translation
– Scaling
– Rotation
– Shear
– And others, e.g., perspective transform, projection, etc.
• Basic types of transformations
– Rigid-body: preserves length and angle
– Affine: preserves parallel lines, not angles or lengths
– Free-form: anything goes
© Machiraju/Zhang/Möller 5
Translation in 2D
P =P +T
!
© Machiraju/Zhang/Möller 6
Scaling in 2D
P =S×P
!
x! = sx × x
y = sy × y
!
• Uniform sx = sy
P ! = SHy × P
! " ! "! "
x!
1 0 x
=
y! b 1 y
P = SHx × P
!
! " ! "! "
x!
1 a x x! = x + ay
=
y! 0 1 y y! = y
© Machiraju/Zhang/Möller 10
Homogeneous coordinates
• Only translation cannot be expressed as
matrix-vector multiplications
• But we can add a third coordinate –
Homogeneous coordinates for 2D points
– (x, y) turns into (x, y, W)
– if (x, y, W) and (x', y', W’ ) are multiples of one
another, they represent the same point
– typically, W ≠ 0.
– points with W = 0 are points at infinity
© Machiraju/Zhang/Möller 11
2D Homogeneous Coordinates
• Cartesian coordinates of the homogenous point
(x, y, W): x/W, y/W (divide through by W)
• Our typical homogenized points: (x, y, 1)
• Connection to 3D?
– (x, y, 1) represents a 3D
point on the plane W = 1
– A homogeneous point is a
line in 3D, through the origin
© Machiraju/Zhang/Möller 12
Transformation in
homogeneous coordinates
• General form of affine (linear) transformation
• E.g., 2D translation in
homogeneous coordinates
© Machiraju/Zhang/Möller 13
Homogeneous Coords (3)
• 2D line equation
– Duality of 3D points to a line ax + by + c = 0
! " x
a b c y =0
• 3D plane equation: 1
– Duality of 4D points to a plane
ax + by + cx + d = 0
x
! " y
• Homog. Coords in 1D? a b c d z
=0
1
© Machiraju/Zhang/Möller 14
Basic 2D transformations
© Machiraju/Zhang/Möller 15
Inverse of transformations
• Inverse of T(dx, dy) = T(−dx, −dy)
• Sh(ax)−1 = Sh(−ax)
© Machiraju/Zhang/Möller 16
Compound transformations
• Often we need many transforms to build
objects (or to “direct” them)
– e.g., rotation about an arbitrary point/line?
• Concatenate basic transforms sequentially
• This corresponds to multiplication of the
transform matrices, thanks to homogeneous
coordinates
© Machiraju/Zhang/Möller 17
Compound translation
• What happens when a point goes through
T(dx1, dy1) and then T(dx2, dy2)?
• Combined translation: T(dx1+dx2, dy1+dy2)
1 0 dx2 1 0 dx1 1 0 dx1 + dx2
0 1 d y2 0 1 d y1 = 0 1 d y1 + d y2
0 0 1 0 0 1 0 0 1
© Machiraju/Zhang/Möller 18
Compound rotation
• What happens when a point goes through
R(θ) and then R(φ)?
• Combined rotation: R(θ + φ)
© Machiraju/Zhang/Möller 21
Rotation about an arbitrary
point
• Break it down into easier problems:
– Translate to the origin: T(−x1, −y1)
– Rotate: R(q)
– And translate back: T(x1, y1)
© Machiraju/Zhang/Möller 22
Rotation about an arbitrary
point
• Compound transformation (non-commutative):
T(x1, y1) • R(q) • T(− x1, − y1)
– P’ = T(x1, y1)R(q)T(− x1, − y1)P = TP
– Why combine these matrices into a single T?
© Machiraju/Zhang/Möller 23
Another example
• Compound transformation:
T(x2, y2) • R(90o) • S(sx, sy) • T(−x1, −y1)
© Machiraju/Zhang/Möller 24
Rigid-body transformation
• A transformation matrix
© Machiraju/Zhang/Möller 25
Affine transformation
• Preserves parallelism, not lengths or angles
© Machiraju/Zhang/Möller 28
Window-To-Viewport
Transformation (2)
• Important example of compound transform
• one can specify a non-uniform scaling
• resulting in distorted images
• What property of window and viewport
indicates whether the mapping will distort the
images?
© Machiraju/Zhang/Möller 29
Window-To-Viewport
Transformation (3)
• Specify transform in matrix form
© Machiraju/Zhang/Möller 30