0% found this document useful (0 votes)
31 views30 pages

2D Transformations: CMPT 361 Introduction To Computer Graphics Torsten Möller

2D Transformations CMPT 361 Introduction to Computer Graphics Torsten Moller Graphics Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Interaction Color Texture / Realism 2.

Uploaded by

Sumit Narang
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views30 pages

2D Transformations: CMPT 361 Introduction To Computer Graphics Torsten Möller

2D Transformations CMPT 361 Introduction to Computer Graphics Torsten Moller Graphics Pipeline Hardware Modelling Transform Visibility Illumination + Shading Perception, Interaction Color Texture / Realism 2.

Uploaded by

Sumit Narang
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

2D Transformations

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
!

! " ! " ! "


x = x + dx
!
x! x dx
! = +
y = y + dy
! y y dy

© Machiraju/Zhang/Möller 6
Scaling in 2D

P =S×P
!

x! = sx × x
y = sy × y
!

• Uniform sx = sy

• Non-uniform sx != sy! " ! " ! "


x! sx 0 x
= ×
y! 0 sy y
© Machiraju/Zhang/Möller 7
Rotation about origin
• Positive angles:
counterclockwise
• For negative angles
cos(−α) = cos(α)
sin(−α) = − sin(α)
P! = R × P
x! = x cos(α) − y sin(α)
y ! = x sin(α) + y cos(α)
! ! " ! "! "
x cos(α) − sin(α) x
=
y !
sin(α) cos(α)
© Machiraju/Zhang/Möller
y 8
Derivation of rotation matrix
• Make use of polar coordinates: (r, φ) → (x, y)
x = r cos(φ) x = r cos(φ + α)
y = r sin(φ) y = r sin(φ + α)
x! = r cos(φ + α) (r, φ) → (x, y)
= r cos(φ) cos(α) − r sin(φ) sin(α)
= x cos(α) − y sin(α)
y ! = r sin(φ + α)
= r sin(φ) cos(α) + r cos(φ) sin(α)
= y cos(α) + x sin(α)
© Machiraju/Zhang/Möller 9
Shearing in 2D

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)

T(−dx, −dy) = T(dx, dy)−1


• R(θ)−1 = R(−θ)
• S(sx, sy)−1 = S(1/sx, 1/sy)

• 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

Concatenation of transformations: matrix multiplication

© Machiraju/Zhang/Möller 18
Compound rotation
• What happens when a point goes through
R(θ) and then R(φ)?
• Combined rotation: R(θ + φ)

• Scaling or shearing (in one direction) is similar


• These concatenations are commutative
© Machiraju/Zhang/Möller 19
Commutativity
• Transformations that do commute:
– Translate – translate
– Rotate – rotate
– Scale – scale
– Uniform scale – rotate
– Shear in x (y) – shear in x (y), etc.
• In general, the order in which transformations
are composed is important
• After all, matrix multiplications are not
commutative © Machiraju/Zhang/Möller 20
Commutativity
• the order in which we compose matrices is
important: matrix multiplication does not
commute

© 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

• where the upper 2 × 2 submatrix is


orthonormal, preserves angles and lengths
– called rigid-body transformation
– any sequence of translation and rotation give a
rigid-body transformation

© Machiraju/Zhang/Möller 25
Affine transformation
• Preserves parallelism, not lengths or angles

Unit cube Rot(−45o) Scale in x

• Product of a sequence of translation, scaling,


rotation, and shear is affine
• In general, A is affine if A(u) = L(u) + w, for
linear transformation L and constant vector w
© Machiraju/Zhang/Möller 26
Types of Transforms
• Continuous/Discrete, one to one ; invertible
• Classification
– Euclidean (similarity: preserves angles)
• Euclidean (translation, rotation, uniform scale)
– Affine (preserves parallel lines)
• Euclidean plus non-uniform scale, shearing
– Projective (preserves lines)
– Isometric (preserves distance)
• Reflection, rigid body motion
– Nonlinear (lines©become curves)
Machiraju/Zhang/Möller 27
• Twists, Bends, warps, morphs
Window-To-Viewport
Transformation
• Important example of compound transform
• “World coords”: space users work in
• need to map world to the screen
– window in world-coordinate space and
– viewport in screen coordinate space

© 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

! " ! umax −umin " ! "


umin −xmin
Mwv = T ×S xmax −xmin
vmax −vmin ×T
vmin ymax −ymin −ymin

© Machiraju/Zhang/Möller 30

You might also like