0% found this document useful (0 votes)
54 views

2D Geometrical Transformations: Foley & Van Dam, Chapter 5

The document discusses 2D geometric transformations including translation, scaling, rotation, shear, and their representation using matrix notation. Transformations can be combined through composition and represented as a single matrix. Homogeneous coordinates allow all transformations to be represented uniformly by matrix multiplication. Common transformations like translation, rotation, and scaling are demonstrated.

Uploaded by

Vincent Vetter
Copyright
© © All Rights Reserved
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)
54 views

2D Geometrical Transformations: Foley & Van Dam, Chapter 5

The document discusses 2D geometric transformations including translation, scaling, rotation, shear, and their representation using matrix notation. Transformations can be combined through composition and represented as a single matrix. Homogeneous coordinates allow all transformations to be represented uniformly by matrix multiplication. Common transformations like translation, rotation, and scaling are demonstrated.

Uploaded by

Vincent Vetter
Copyright
© © All Rights Reserved
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/ 34

2D Geometrical Transformations

Foley & Van Dam, Chapter 5

2D Geometrical Transformations
Translation

Scaling
Rotation
Shear
Matrix notation
Compositions
Homogeneous coordinates

2D Geometrical Transformations
Assumption: Objects consist of points and lines.
A point is represented by its Cartesian coordinates:
P = (x, y)
Geometrical Transformation:
Let (A, B) be a straight line segment between the
points A and B.
Let T be a general 2D transformation.
T transforms (A, B) into another straight line segment
(A, B), where:
A=TA and
B=TB

Translation
Translate(a, b): (x, y) (x+a, y+b)

Translate(2, 4)

Scale
Scale (a, b):

(x, y) (ax, by)

Scale (2, 3)

Scale (2, 3)

Scale
How can we scale an object without

moving its origin (lower left corner)?


Translate(-1,-1)

Translate(1,1)

Scale(2,3)

Reflection
Special case of scale
Scale(-1,1)

Scale(1,-1)

Rotation
Rotate():
(x, y) (x cos()+y sin(), -x sin()+y cos())
Rotate(90)

Rotate(90)

Rotation
How can we rotate an object without

moving its origin (lower left corner)?


Translate(-1,-1)

Translate(1,1)
Rotate(90)

Shear
Shear (a, b): (x, y) (x+ay, y+bx)
Shear(1,0)

Shear(0,2)

Classes of Transformations
Rigid transformation (distance preserving):
Translation + Rotation
Similarity transformation (angle preserving):
Translation + Rotation + Uniform Scale
Affine transformation (parallelism preserving):
Translation + Rotation + Scale + Shear
All above transformations
are groups where
Rigid Similarity Affine

Affine
Similarity
Rigid

Matrix Notation
Lets treat a point (x, y) as a 2x1 matrix
(column vector):
x
y

What happens when this vector is multiplied
by a 2x2 matrix?
a
c

b x
ax
=

d y
cx

+ by
+ dy

2D Transformations
2D object is represented by points and lines
that join them
Transformations can be applied only to the the
points defining the lines
A point (x, y) is represented by a 2x1 column
vector, so we can represent 2D transformations
by using 2x2 matrices:
b x
x '
a
y ' = c
y
d

Scale
Scale (a, b):
a
0

(x, y) (ax, by)


0 x
ax
=
by
b y

If a or b are negative, we get reflection


Inverse: S-1(a,b) = S(1/a, 1/b)

Reflection
Reflection through the y axis:
1
0

0
1

Reflection through the x axis:


1
0

0
1

Reflection through y = x:
0
1

1
0

Reflection through y = -x:


0
1

1
0

Shear
Shear (a, b): (x, y) (x+ay, y+bx)
1
b

a x
x + ay
=

1 y
y + bx

Rotation
Rotate():
(x, y) (x cos()+y sin(), -x sin()+y cos())

cos
sin

sin x x cos + y sin


=

cos y x sin + y cos

Inverse: R-1(q) = RT(q) = R(-q)

Composition of Transformations
A sequence of transformations can be
collapsed into a single matrix:
x
x
[ A ][B ][C ] = [D ]
y
y
Note: Order of transformations is important!
translate

rotate

rotate

translate

Translation
Translation (a, b):
x
y

x + a
y + b

Problem: Cannot represent translation


using 2x2 matrices
Solution:
Homogeneous Coordinates

Homogeneous Coordinates
Is a mapping from Rn to Rn+1:

( x , y ) ( X , Y , W ) = ( tx , ty , t )
Note: All triples (tx, ty, t) correspond to the
same non-homogeneous point (x, y)
Example (2, 3, 1) (6, 9, 3).
Inverse mapping:

( X ,Y ,W )

Y
,
W

Translation
Translate(a, b):
1
0

0
1
0

a
b
1

x
x + a
y = y + b

Inverse: T-1(a, b) = T(-a, -b)


Affine transformations now have the
following form:
a
c

b
d

e
f
1

Geometric Interpretation
A 2D point is mapped to a line (ray) in 3D
The non-homogeneous points are obtained
by projecting the rays onto the plane Z=1
W
Y
1

y
x

(X,Y,1)

(X,Y,W)

Example
Rotation about an arbitrary point
(x0,y0)

1. Translate the coordinates so that the origin is at (x0,y0)


2. Rotate by
3. Translate back
1
0

0
1
0

cos
= sin

x
y

0
1
0

cos
sin

sin
cos
0

sin
cos
0

0 1
0 0
1 0

( 1 cos ) + y
y 0 ( 1 cos ) x

0
0

0
1

x
y

sin
sin

0
0

x
y

1

x
y =

1

Example
Reflection about an arbitrary line
p2
p1

L = p1 + t (p2-p1) = t p2 + (1-t) p1

1. Translate the coordinates so that P1 is at the


origin
2. Rotate so that L aligns with the x-axis
3. Reflect about the x-axis
4. Rotate back
5. Translate back

Change of Coordinates
It is often required to transform the description of an
object from one coordinate system to another
Rule: Transform one coordinate frame towards the
other in the opposite direction of the representation
change
ion
R ep

tat
n
e
res

Tra

ion
t
a
rm
o
f
s
n

Example
Change of coordinates: Represent P = (xp, yp, 1)
in the (x, y) coordinate system

P ' = MP
Where:
M

cos

= sin

sin
cos
0

0
0
1

0
0

(x0, y0)

(xp, yp)

0
1
0

x
y
1

0
0

Example
Change of coordinates:
Alternative method: assume x = (ux, uy) and
y = (vx, vy) in the (x, y) coordinate system

P ' = MP

where
M

u x

= v x
0

y
(vx, vy)

0 1

0 0
1 0

y
(ux, uy)

x
(x0, y0)

Example
Reflection about an arbitrary line
p2

L = p1 + t (p2-p1) = t p2 + (1-t) p1

p1

Define a coordinate systems (u, v) parallel to


P1P2:
p2 p1
u x
u =

p1

u
v =
u

M = 0
0

0
1
0

p 1x
p 1y
1

u x

u y
0

vx
vy
0

y
x

0 1

0 0
0

= v

0
1
0

y
x
y

0 u x
0 v x
1 0

uy
vy
0

0 1

0 0
1 0

0
1
0

p 1x
p 1y
1

3D Viewing Transformation Pipeline


Viewing coordinates
World Coordinates

Object in World

D
2
:
D

ing
p
ap

2D:2D mapping

Viewport

Device Coordinates

World to Viewing Coordinates


In order to define the viewing window we have to
specify:
Windowing-coordinate origin P0 = (x0,y0)
View vector up v = (vx,vy)
Using v, we can find u: u = v x (0,0,1)
yv

y world

ie w

(x0,y0)x v

(vx,vy).
ie w

x world

(ux,uy).

Transformation from world to viewing coordinates :


M

wc vc

ux

= vx
0

uy
vy
0

0 1

0 0
1 0

0
1
0

x0
y 0
1

Window to Viewport Coordinates


(xmax,ymax)
(xmin,ymin)
Window translated to origin

Window is Viewing Coordinates


(umaxn,vmaxn)

(umin,vmin)
Window scaled and translated to
Viewport location in device coordinates

1 0 u min u max u min

0
M vc dc= 0 1 v min
0 0
1
0

0
v max v min
0

0 x max

Window scaled to Normalized


Viewport size

1
x min
0
0

0
y max

1
y min
0

0
1
0 0

1 0

0
1
0

x min

y min
1

Normalized Device Coordinates

Efficiency Considerations
A 2D point transformation requires 9 multiplies and 6
adds
a
d

b
e
h

c
f
i

x
ax + by + cz
y = d x + e y + fz

z
g x + h y + i z

But since affine transformations have always the form:


b
c x
a
ax + by + c
d

f y = dx + ey + f
e

0
1 1
1
The number of operations can be reduced to 4
multiplies and 4 adds

Efficiency Considerations
The rotation matrix is:

cos
sin

sin x x cos + y sin


=

cos y x sin + y cos

When rotating of small angles , we can use the fact


that cos() 1 and simplify

sin

sin x x + y sin
=

1 y x sin + y

Determinant of a Matrix

a
c

b
= ad bc
d

aei + bfg + cdh ceg afh bdi

+c

If P is a polygon of area AP, transformed by a matrix


M, the area of the transformed polygon is AP|M|

You might also like