Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Affine transformations
Transformations in 3D
Lecture 5
Linear and affine transformations
a11 x + a12 y
a11 a12 x
In 2D: =
a21 a22 y a21 x + a22 y
Example: scaling
2 0
0 2
to a vector:
2 0 2x + 0y 2x
x
= =
0 2 y 0x + 2y 2y
Linear transformations
A function T : Rn Rm is called a
linear transformation if it satisfies
u+v
1 T (~u + ~v ) = T (~u) + T (~v ) for all v
~u, ~v Rn .
u
2 T (c~v ) = cT (~v ) for all ~v Rn and
all scalars c. T (u + v)
T (v)
Or (alternatively), if it satisfies
T (c1 ~u + c2~v ) = c1 T (~u) + c2 T (~v )
for all ~u, ~v Rn and all scalars c1 , c2 . T (u)
Example: scaling
In general, a matrix
a11 0
0 a22
a11 0 a11 x + 0y
x a11 x
= =
0 a22 y 0x + a22 y a22 y
Example: scaling
Scaling does not have to be
uniform. Here, we scale with a
factor one half in x-direction,
and three in y-direction:
2 0
1 1
x x
= 2
0 3 y 3y
Example: scaling
1
0 1 0
2
0 3 0 1
(Gaussian elimination)
1 0 2 0
0 1 0 13
Example: projection
We can also use matrices to
do orthographic projections,
for instance, onto the Y -axis:
0 0 0
x
=
0 1 y y
Example: reflection
Reflection in the line y = x
boils down to swapping x- and
y-coordinates:
0 1
x y
=
1 0 y x
Example: shearing
Shearing in x-direction
pushes things sideways:
1 1 x+y
x
=
0 1 y y
1 0
x x
=
1 1 y x+y
Example: shearing
1 s x + sy
x
=
0 1 y y
1 s
x x sy
=
0 1 y y
Example: rotation
Note: 22 = cos 45 = sin 45 ,
so this is the same as
cos 45 sin 45
sin 45 cos 45
Example: rotation
cos sin
sin cos
cos sin
sin cos
Finding matrices
Finding matrices
Lets apply some transformations to the base vectors b~1 = (1, 0) and
b~2 = (0, 1) of the carthesian coordinates system, e.g.
a 0 x ax
Scaling (factors a, b 6= 0): =
0 b y by
1 s x x + sy
Shearing (x-dir., factor s): =
0 1 y y
0 1 x y
Reflection (in line y = x): =
1 0 y x
1 1 x xy
Rotation (countercl., 45 ): 2
2
= 2
2
1 1 y x+y
Finding matrices
Finding matrices
Remember: T is a linear transformation if and only if
T (c1 ~u + c2~v ) = c1 T (~u) + c2 T (~v )
1 0
x
~=
w =x +y
y 0 1
1 0 1 0
x
T( ) = T (x +y ) = xT ( ) + yT ( )
y 0 1 0 1
5 0 0 1 0 5
x x
=
0 2 1 0 y 2 0 y
5 0 0 1 0 5 5y
x x
= =
0 2 1 0 y 2 0 y 2x
0 1 5 0 0 2 2y
x x
= =
1 0 0 2 y 5 0 y 5x
y + yt
Homogeneous coordinates
Observation:
Shearing in 2D smells a lot like
translation in 1D . . .
Homogeneous coordinates
. . . and shearing in
3D smells like
translation in 2D
(. . . and shearing in
4D . . . )
x + xt
x
M y = y + yt
d d
Homogeneous coordinates
1 0 xt x + xt d
x
0 1 yt y = y + yt d
0 0 1 d d
1 0 xt x + xt
x
0 1 yt y = y + yt
0 0 1 1 1
1 0 xt x + xt
x
0 1 yt y = y + yt
0 0 1 1 1
1 0 xt
x x
0 1 yt y = y
0 0 1 0 0
Homogeneous coordinates
1. Translation of y = x + 5 to y = x
1 0 xt x x + xt 1 0 .
0 1 yt y = y + yt 0 1 .
0 0 1 1 1 0 0 1
2. Reflection on y = x: 0 1 . . . .
1 0 . . . .
0 1 . . . . . .
1 0
1 0 . . . .
3. Translate y = x back to y = x + 5 0 1 . . . .
0 0 1 . . .
Affine transformations
0 1 5
1 0 5
0 0 1
Affine transformations
Linear transformations in 3D
In general, linear transformations in 3D are a straightforward
extension of their 2D counterpart.
We have already seen an example: shearing in x ydirection
1 0
dx
0 1 dy
0 0 1
Or in general
1 dx2 dx3
dy1 1 dy3
0 0 1
Affine transformations in 3D
0 0 0 1
x x
y y
points:
z and vectors: z
1 0
Transformations in 3D
For scaling, we have three scaling factors on the diagonal of the
matrix.
0 0
sx
0 sy 0
0 0 sz
1 x + dy y + dz z
dx2 dx3 x
0 1 0 y = y
0 0 1 z z
Transformations in 3D
Rotation in 2D (x y-plane):
cos sin
sin cos
We need a 3D transformation
that rotates around an
arbitrary vector w.
~
How can we do that?
Idea:
1 Rotate vector w
~ to z-axis
2 Do 3D rotation around
z-axis
3 Rotate everything back to
original position
cos sin 0
sin cos 0
0 0 1
cos sin 0
? sin cos 0 ?
0 0 1
cos sin 0
xu xv xw
yu yv yw sin cos 0 ?
zu zv zw 0 0 1
Graphics 2011/2012, 4th quarter Lecture 5: linear and affine transformations
Linear transformations Moving up a dimension
Affine transformations Rotations in 3D
Transformations in 3D Reflections in 3D
cos sin 0
xu xv xw
yu yv yw sin cos 0 ?
zu zv zw 0 0 1
But thats just the inverse of the other rotation matrix.
Note: if we assume that k~uk = k~v k = kwk~ = 1 we dont even need
to calculate it, because the inverse of an orthogonal matrix is
always its transposed!
cos sin 0
xu xv xw x u yu zu
yu yv yw sin cos 0 xv yv zv
z u zv zw 0 0 1 x w yw zw
1 0 0
0 1 0
0 0 1