2D Geometrical Transformations: Foley & Van Dam, Chapter 5
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):
Scale (2, 3)
Scale (2, 3)
Scale
How can we scale an object without
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
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
Reflection
Reflection through the y axis:
1
0
0
1
0
1
Reflection through y = x:
0
1
1
0
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
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
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
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)
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
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
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
Object in World
D
2
:
D
ing
p
ap
2D:2D mapping
Viewport
Device Coordinates
y world
ie w
(x0,y0)x v
(vx,vy).
ie w
x world
(ux,uy).
wc vc
ux
= vx
0
uy
vy
0
0 1
0 0
1 0
0
1
0
x0
y 0
1
(umin,vmin)
Window scaled and translated to
Viewport location in device coordinates
0
M vc dc= 0 1 v min
0 0
1
0
0
v max v min
0
0 x max
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
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
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
sin x x + y sin
=
1 y x sin + y
Determinant of a Matrix
a
c
b
= ad bc
d
+c