05 2d Transformations

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

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.

 David F. Rogers and J. Alan Adams,


Mathemati al Elements for Computer

Graphi s, Se ond edition, M Graw-Hill,


New York, 1990, Chapter 2.

2
2D drawing

Think of a program like PowerPoint,


Illustrator, Ma Draw...
 Intera tively reate a number of primitives,
e.g., polygons and ir les.
 Indi ate a front-to-ba k ordering.
 S ale, translate, and rotate obje ts, as well
as group them together.
 S roll or zoom the \ anvas" to look at
di erent parts of the drawing.
 Generate an image and displays it on the
s reen.

3
2D drawing, ont'd

What are some of the key ingredients needed


to make this work?
 Spe i ation of the front-to-ba k ordering.
 A sequen e of geometri transformations,
some of them stored in hierar hies
orresponding to groups of primitives.
 De nition of the \visible" portion of the
anvas.
 A mapping from the visible portions of the
anvas to pixels on the s reen.
 Software or hardware that is able to
\rasterize" the primitives, i.e., draw the
pixels orresponding to the primitives.

4
2D geometry pipeline

Let's think about this in terms of a set of


oordinate systems:
y1 y2
Model space
x1 x2 (Object space)

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

To avoid drawing primitives or parts of


primitives that do not appear in the viewport,
we perform \ lipping".

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

Here's an example of an OpenGL program


that will draw a bla k square over a white
ba kground:

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();

For the remainder of this le ture, we will fo us


on 2D geometri transformations...

7
Representation

We an represent a point p = (x; y ) in the


plane
2 3

 as a olumn ve tor 6 x 7
6
4
7
5
y

 as a row ve tor
 
x y

8
Representation, ont.

We an represent a 2-D transformation M


by a matrix
2 3
6 a b 7
6 7
4 5
d

If p is a olumn ve tor, M goes on the left:


p
0
= M p
2 3 2 3 2 3
0
6 x 7 6 a b 7 6 x 7
6
4
7
0 5
= 6
4
7 6
5 4
7
5
y d y

If p is a row ve tor, M T goes on the right:


p
0
= pT
2 3
   
6 a 7
0
x y
0
= x y 6
4
7
5
b d

We will use olumn ve tors.

9
Two-dimensional transformations

Here's all you get with a 2  2 transformation


matrix M :
2 3 2 3 2 3
0
6 x 7 6 a b 7 6 x 7
6
4
7
0 5
= 6
4
7 6
5 4
7
5
y d y

So
x
0
= ax + by
y
0
= x + dy

We will develop some intima y with the


elements a; b; ; d. . . .

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

 Doesn't move the points at all

11
S aling

Suppose we set b = = 0, but let a and d take


on any positive value:
 Gives a \s aling" matrix
2 3
6 a
6
0 77
4 5
0 d

 Provides di erential s aling in x and y :


x
0
= ax

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

E e t is alled a \ ."

14
E e t on unit square

Let's see how a general 2  2 transformation


M a e ts the 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
E e t on unit square, ont.

Observe:
 Origin invariant under M

 an be determined just by knowing how


M

the orners (1; 0) and (0; 1) are mapped


 a and d give x- and y -s aling
 b and give x- and y -shearing

16
Rotation

From our observations of the e e t on the unit


square, it should be easy to write down a
matrix for \rotation about the origin":

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

Idea is to loft the problem up into 3-spa e,


adding a third omponent to every point:
2 3
2 3
6 x 7

!
6 7
6 x 7 6 7
6 7 6 y 7
4 5 6 7
6 7
y 4 5
1

And then2 transform


3 2
with a3 32  33 matrix:
6 1 0 m 7 6 x 7
0
6 x 7
6 7 6 7 6 7
6 7 6 7 6 7
6 y 7 = 6 0 1 n 7 6 y 7
0
6 7 6 7 6 7
6 7 6 7 6 7
4 5 4 5 4 5
w
0
0 0 1 1

. . . Gives translation!
19
Rotation about arbitrary points

Until now, we have only onsidered rotation


about the origin.

With homogeneous oordinates, you an


spe ify rotations about any point q with a
matrix:

1. Translate q to origin
2. Rotate
3. Translate ba k to q

Note: Transformation order is important!


20
Window-to-viewport transformation

How do we transform from the window in


world oordinates to the viewport in s reen
spa e?
yw
World space Normalized device
y space
s

ywmax
window
yvmax viewport
ywmin yvmin
xw xs
xwmin xwmax xvmin xvmax

21
Mathemati s of aÆne transformations

All of the transformations we've looked at so


far are examples of \aÆne transformations."

Here are some useful properties of aÆne


transformations:
 Lines map to lines
 Parallel lines remain parallel
 Midpoints map to midpoints
(in fa t, ratios are always preserved)

22
Summary

What to take away from this le ture:


 All the underlined names and names in
quotations.
 How points and transformations are
represented.
 What all the elements of a 2  2
transformation matrix do.
 What homogeneous oordinates are and
how they work for aÆne transformations.
 How to on atenate transformations.
 The mathemati al properties of aÆne
trasnformations.

23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy