You are on page 1of 32

# Machiraju/Zhang/Mller

2D Transformations
CMPT 361
Introduction to Computer Graphics
Torsten Mller
Machiraju/Zhang/Mller
2
Graphics Pipeline
Hardware
Modelling Transform Visibility
Illumination +
Color
Perception,
Interaction
Texture/
Realism
Machiraju/Zhang/Mller
3
Chapter 3 of Angel
Chapter 5 of Foley, van Dam,
Machiraju/Zhang/Mller
4
Schedule
Geometry basics
Afne transformations
Use of homogeneous coordinates
Concatenation of transformations
3D transformations
Transformation of coordinate systems
Transform the transforms
Transformations in OpenGL
Machiraju/Zhang/Mller
5
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
Afne: preserves parallel lines, not angles or lengths
Free-form: anything goes
Machiraju/Zhang/Mller
6
Translation in 2D
P

= P +T
x

= x +d
x
y

= y +d
y

x
y

d
x
d
y

Machiraju/Zhang/Mller
7
Scaling in 2D

s
x
0
0 s
y

x
y

= S P
x

= s
x
x
y

= s
y
y
Uniform s
x
= s
y
Non-uniform s
x
= s
y
Machiraju/Zhang/Mller
Positive angles:
counterclockwise
For negative angles
8
P

= R P
x

= xcos() y sin()
y

= xsin() + y cos()
cos() = cos()
sin() = sin()

cos() sin()
sin() cos()

x
y

Machiraju/Zhang/Mller
Make use of polar coordinates:
9
Derivation of rotation matrix
x = r cos()
y = r sin()
x = r cos( +)
y = r sin( +)
x

= r cos( +)
= r cos() cos() r sin() sin()
= xcos() y sin()
y

= r sin( +)
= r sin() cos() + r cos() sin()
= y cos() + xsin()
(r, ) (x, y)
(r, ) (x, y)
Machiraju/Zhang/Mller
10
Shearing in 2D
P

= SH
y
P
P

= SH
x
P

1 a
0 1

x
y

1 0
b 1

x
y

= x +ay
y

= y
Machiraju/Zhang/Mller
11
Schedule
Geometry basics
Afne transformations
Use of homogeneous coordinates
Concatenation of transformations
3D transformations
Transformation of coordinate systems
Transform the transforms
Transformations in OpenGL
Machiraju/Zhang/Mller
12
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 innity
Machiraju/Zhang/Mller
13
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/Mller
14
Transformation in
homogeneous coordinates
General form of afne (linear) transformation
E.g., 2D translation in
homogeneous coordinates
Machiraju/Zhang/Mller
2D line equation
Duality of 3D points to a line
3D plane equation:
Duality of 4D points to a plane
Homog. Coords in 1D?
15
Homogeneous Coords (3)
ax + by + cx + d = 0

a b c d

x
y
z
1

= 0
ax + by + c = 0

a b c

x
y
1

= 0
Machiraju/Zhang/Mller
16
Basic 2D transformations
Machiraju/Zhang/Mller
17
Inverse of transformations

Inverse of T(d
x
, d
y
) = T("d
x
, "d
y
)
R(#)
!1
= R("#)

S(s
x
, s
y
)
!1
= S(1/s
x
, 1/s
y
)

Sh(a
x
)
!1
= Sh("a
x
)
T("d
x
, "d
y
) = T(d
x
, d
y
)
!1
Machiraju/Zhang/Mller
18
Schedule
Geometry basics
Afne transformations
Use of homogeneous coordinates
Concatenation of transformations
3D transformations
Transformation of coordinate systems
Transform the transforms
Transformations in OpenGL
Machiraju/Zhang/Mller
19
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/Mller
20
Compound translation
What happens when a point goes through
T(d
x1
, d
y1
) and then T(d
x2
, d
y2
)?

## Combined translation: T(d

x1
+d
x2
, d
y1
+d
y2
)
Concatenation of transformations: matrix multiplication

1 0 d
x
2
0 1 d
y
2
0 0 1

1 0 d
x
1
0 1 d
y
1
0 0 1

1 0 d
x
1
+ d
x
2
0 1 d
y
1
+ d
y
2
0 0 1

Machiraju/Zhang/Mller
21
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/Mller
22
Commutativity
Transformations that do commute:
Translate translate
Rotate rotate (around the same axis)
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/Mller
23
Commutativity
the order in which we compose matrices is
important: matrix multiplication does not
commute
x
y
z
x
y
z
x
y
z
x
y
z
x
y
z
X then Z
Z then X
Machiraju/Zhang/Mller
24
arbitrary point
Break it down into easier problems:
Translate to the origin: T("x
1
, "y
1
)
Rotate: R(q)
And translate back: T(x
1
, y
1
)
Machiraju/Zhang/Mller
25
arbitrary point
Compound transformation (non-commutative):
T(x
1
, y
1
) R(q) T(" x
1
, " y
1
)
P = T(x
1
, y
1
)R(q)T(" x
1
, " y
1
)P = AP
Why combine these matrices into a single A?
Machiraju/Zhang/Mller
26
Another example
Compound transformation:
T(x
2
, y
2
) R(90
o
) S(s
x
, s
y
) T("x
1
, "y
1
)
Machiraju/Zhang/Mller
27
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/Mller
28
Afne transformation
Preserves parallelism, not lengths or angles
Product of a sequence of translation, scaling,
rotation, and shear is afne
Unit cube Rot("45
o
) Scale in x
Machiraju/Zhang/Mller
29
Types of Transforms
Continuous/Discrete, one to one ; invertible
Classication
Euclidean (preserves angles)
translation, rotation, uniform scale
Afne (preserves parallel lines)
Euclidean plus non-uniform scale, shearing
Projective (preserves lines)
Isometry (preserves distance)
Reection, rigid body motion
Nonlinear (lines become curves)
Twists, Bends, warps, morphs
Machiraju/Zhang/Mller
30
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/Mller
one can specify non-uniform scaling
results in distorted images
What property of window and viewport
indicates whether the mapping will distort the
images?
31
Window-To-Viewport
Transformation (2)
Machiraju/Zhang/Mller
32
Window-To-Viewport
Transformation (3)
Specify transform in matrix form
M
wv
= T

u
min
v
min

u
max
u
min
x
max
x
min
v
max
v
min
y
max
y
min

x
min
y
min