05 2d Transformations
05 2d Transformations
05 2d Transformations
1
Reading
Required:
Hearn and Baker, Se
tions 5.1{5.4, 5.6,
6.1{6.3, 6.5
Optional:
Foley , Chapter 5.1{5.5
et al.
2
2D drawing
3
2D drawing,
ont'd
4
2D geometry pipeline
scale, translate,
yw rotate, ...
window
World space
(Object space)
xw
scale, translate
ys
1.0 Normalized device space
viewport
(Screen space)
xs
1.0 scale
yi Image space
(Window space)
(Raster space)
(Screen space)
xi (Device space)
5
Clipping
Clipping in
ludes:
Removal of primitives wholly outside of the
viewport (a.k.a., \
ulling")
Interse
tion of the viewport with primitives
that straddle the viewport boundary.
Clipping
an happen:
In world spa
e
In normalized devi
e spa
e
In image spa
e
6
A simple OpenGL example
makeADrawingWindow();
glOrtho(xw_min, xw_max, yw_min, yw_max, -1.0, 1.0);
glViewport(xi_min, yi_min, width_i, height_i);
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex2f(0.0, 0.0);
glVertex2f(1.0, 0.0);
glVertex2f(1.0, 1.0);
glVertex2f(0.0, 1.0);
glEnd();
glFlush();
7
Representation
as a
olumn ve
tor 6 x 7
6
4
7
5
y
as a row ve
tor
x y
8
Representation,
ont.
9
Two-dimensional transformations
So
x
0
= ax + by
y
0
=
x + dy
10
Identity
Suppose we
hoose a = d = 1, b =
= 0:
Gives the \identity" matrix
2 3
6
6
1 0 77
4 5
0 1
11
S
aling
y
0
= dy
12
Suppose we keep b =
= 0, but let a and d go
negative.
Examples:
2 3 2 3
6
6
1 0 77 6
6
1 0 77
4 5 4 5
0 1 0 1
13
Now let's leave a = d = 1 and experiment
with
. . . .
The matrix
2 3
6 1 0 7
6 7
4 5
1
gives:
x
0
= x
y
0
=
x +y
Ee t is alled a \ ."
14
Ee
t on unit square
2 3 2 3 2 3
6 a b 7 6 0 1 1 0 77 6 0 a a +b b 7
6
4
7 6
5 4 5 = 6
4
7
5
d 0 0 1 1 0
+ d d
15
Ee
t on unit square,
ont.
Observe:
Origin invariant under M
16
Rotation
2 3
1 77
6
6
4
0
5 !
2 3
0 77
6
6
4
1
5 !
17
Limitations of the 2 2 matrix
A 2 2 matrix allows
S
aling
Rotation
Re
e
tion
Shearing
Q: What important operation does that leave
out?
18
Homogeneous
oordinates
!
6 7
6 x 7 6 7
6 7 6 y 7
4 5 6 7
6 7
y 4 5
1
. . . Gives translation!
19
Rotation about arbitrary points
1. Translate q to origin
2. Rotate
3. Translate ba
k to q
ywmax
window
yvmax viewport
ywmin yvmin
xw xs
xwmin xwmax xvmin xvmax
21
Mathemati
s of aÆne transformations
22
Summary
23