You are on page 1of 14

Review

2D Transformations

Matrix Composition

Homogeneous . . .

Special . . .

Summary Computer Graphics 4:


Exercise 3
2D Geometrical Transformations
Jon Sporring
mailto:sporring@lab3d.odont.ku.dk

October 23, 2001

JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 1. Review


Homogeneous . . .

Special . . .
Last lecture covered Foley et al. pp. 91–99, 110–127, and 132–140
Summary
on:
Exercise 3

• Filling Polygons
• Clipping
• Antialiasing

In this lecture we’ll discuss Foley et al. pp. 201–213 on

• 2D transformations
• Matrix Composition
JJ II
J I • Homogeneous Coordinates

Full Screen
• Special Transformations
Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 2. 2D Transformations


Homogeneous . . .

Special . . .
Consider the implicit surface:
Summary

Exercise 3 F (x, y) = ax + by + c

where F (x, y) = 0 is a line.


Two linear equations (in x and y)

F = ax + by + c,
G = dx + ey + f.

Another way of writing this is


      
F a b x c
= + .
G d e y f
JJ II
J I
This is a affine (linear) transformation of ~x into F~ .
Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 2.1. Translation and Rotation


Homogeneous . . .

Special . . . To gain intuition about the 6 parameters a, b, c, d, e, f reconsider


Summary the equation(s):
Exercise 3       
F a b x c
= + .
G d e y f
Some typical 2-dimensional linear transformations are:

Translation: Point [x, y]T is translated by [c, f ]T when


      
F 1 0 x c
= + .
G 0 1 y f

Scaling: Points [x, y]T are scaled by a and e when


      
F a 0 x 0
JJ II
= + .
G 0 e y 0
J I
Rotation: Points [x, y]T are rotated by θ when
Full Screen       
F cos(θ) − sin(θ) x 0
Close = + .
G sin(θ) cos(θ) y 0
Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 2.2. Mini Exercise: Concatenating Transformations


Homogeneous . . .

Special . . . 1. Assume you are given a set of points [xi , yi ]T , and that the
Summary centroid (mean point) is [mx , my ]. How would you rotate
Exercise 3 the points [xi , yi ]T around the centroid?
2. How would you scale points [xi , yi ]T with constants k1 along
pi/4 and k2 along 3pi/4.
3. Can
 the
 above be written as a single matrix transformation
a b
?
d e

JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 3. Matrix Composition


Homogeneous . . .

Special . . .
   
a11 a12 b11 b12
Summary In general given two matrices, A = and B = ,
a21 a22 b21 b22
Exercise 3
the sequential operation of first multiplying by A and then by
B,

x~0 = A~x,
x~00 = Bx~0 = BA~x,

may be written as a single matrix multiplication

x~00 = C~x,

with  
b11 a11 + b12 a21 b11 a12 + b12 a22
C=
JJ II b21 a11 + b22 a21 b21 a12 + b22 a22
J I or X
cij = bik akj
Full Screen
k
Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 4. Homogeneous Coordinates


Homogeneous . . .

Special . . .
In the above, translation is treated as addition while rotation
Summary
and scaling is treated as multiplication:
Exercise 3

p~0 = ~t + p~
p~0 = S~p
p~0 = R~p

This is notationally inconvenient. Introducing homogeneous co-


ordinates:     
F a b c x
G = d e f  y 
1 0 0 1 1

JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 4.1. Mini Exercise: Homogeneous Coordinates


Homogeneous . . .

Special . . . 1. Given a scaling matrix


Summary
 
s1 0 0
Exercise 3
S(s1 , s2 ) =  0 s2 0
0 0 1
and a translation matrix
 
1 0 t1
T(t1 , t2 ) = 0 1 t2 
0 0 1
is the transformation
ST~x = TS~x ?

2. Show that two successive rotations using a rotation ma-


JJ II
trix in homogeneous coordinates are additive (commuta-
J I
tive). Hint:
Full Screen sin(α + β) = sin(α) cos(β) + cos(α) sin(β)
Close
cos(α + β) = cos(α) cos(β) − sin(α) sin(β)
Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 4.2. Commuting Transformations


Homogeneous . . .

Special . . . Matrix composition is generally not


Ap ABp = BAp?
Summary commutative, i.e. given two arbi-
Exercise 3 trary matrices A and B: AB 6= B
BA. The concept of commuta- A A
tive transformations is sometimes B
depicted as a graph. p Bp

A few exceptions exist:

A B
Translation Translation
Scaling Scaling
Rotation Rotation
JJ II
Rotation Scaling (s1 = s2 )
J I
Translation Centroid Rotation
Full Screen
Translation Centroid Scaling
Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 5. Special Transformations


Homogeneous . . .

Special . . .
Transformations are typically grouped by their action. Consider
Summary
the matrix,
Exercise 3
 
a b c
d e f ,
0 0 1
and the 2 × 2 submatrix:
 
a b
A= .
d e

Orthogonal (Rigid Body)


The matrix A is said to be orthogonal when the vectors
[a, b]T and [d, e]T are perpendicular and have unit length.
JJ II
Preserves lengths and angles.
J I Affine
Arbitrary composition of Translation, Scaling, Rotation, and
Full Screen
Shear.
Close
Preserves parallel lines.
Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 5.1. Shear: Affine, not Orthogonal


Homogeneous . . .

Special . . . An example of a transformation that is affine but not orthogonal


Summary is Shear:  
Exercise 3 1 b 0
H = 0 1 0 ,
0 0 1

Scale Shear

Rotate

Rotate
Non−uniform scale
JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 5.2. Mini Exercise: Orthogonal


Homogeneous . . .

Special . . . 1. Is the Rotation matrix Orthogonal?


Summary

Exercise 3

JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 6. Summary


Homogeneous . . .

Special . . .
This lecture covered Foley et al. pp. 201–213 on:
Summary

Exercise 3
• 2D Transformation
• Matrix Composition
• Homogeneous Coordinates
• Special Transformations

Next will be Foley et al. pp. 213–237, 253–281 on:

• 3D Transformation

JJ II • Projections
J I
• Implementation
Full Screen
• Coordinate Systems
Close

Jon
c Sporring

ITU, Copenhagen
Review

2D Transformations

Matrix Composition 7. Exercise 3


Homogeneous . . .

Special . . .
The purpose of this exercise is to familiarize the student with 2D
Summary
matrix programming.
Exercise 3

1. Write a program to rotate a set of points an arbitrary angle


around the centroid.
2. Write a program that draws a polygon of your choice, and
produce an animation, where the polygon is incrementally
rotated around the centroid.

JJ II
J I

Full Screen

Close

Jon
c Sporring

ITU, Copenhagen

You might also like