Cgsem 4 PPT 3
Cgsem 4 PPT 3
Matrix math
Is there a difference between possible representations?
a b e ae bf
c d f ce df
ce df
a c
ae bf
b d
be df
a b
ae cf
c d
Pick a convention
Well use the column-vector representation for a point.
Which implies that we use pre-multiplication of the
transformation it appears before the point to be
transformed in the equation.
A B x Ax By
C D y Cx Dy
Translation
A translation moves all points in
an object along the same
straight-line path to new
positions.
The path is represented by a
vector, called the translation
or shift vector.
We can write the components:
p'x = px + tx
p'y = py + ty
or in matrix form:
P' = P + T
4
Rotation
A rotation repositions all
points in an object along a
circular path in the plane
centered at the pivot point.
First, well assume the pivot is
at the origin.
More rotation
Another convention, well take to be counterclockwise, as in
our example.
R, the rotation matrix, looks like:
cos
R
sin
( x, y ) (5,1)
90
sin
cos
cos
sin
sin
x x cos y sin
5 sin 90 1 cos 90
5 0 11
5 1 1 0
1
Scaling
Scaling alters the size of an
object. Scales are about the
the origin.
Scale factors between 0 and 1
shrink objects. Scale factors
greater than 1 enlarge objects.
We can write the components:
p'x = sx px
p'y = sy py
or in matrix form:
P' = S P
The scale factors need not be the
same in each direction.
7
More scaling
We write a scale matrix as:
sx
S
0
0
s y
Combining transformations
We have a general transformation of a point:
P' = M P + A
When we scale or rotate, we set M, and A is the additive
identity.
When we translate, we set A, and M is the multiplicative
identity.
To combine multiple transformations, we must explicitly
compute each transformed point.
Itd be nicer if we could use the same matrix operation all the
time. But wed have to combine multiplication and addition
into a single operation.
9
(x,y,1)
(0,0,0)
w=1
x,y
10
So what?
Well, now we can wedge some addition into our multiplicative
matrix.
Our point now has three coordinates. So our matrix is needs
to be 3x3.
We want a matrix which gives us:
x x t x
y y t y
11
Now what?
x 1 x 0 y t x 1
y 0 x 1 y t y 1
1 0 x 0 y 1 1
x 1 0 t x x
y 0 1 t y
y
1 0 0 1 1
12
And?
Rotations:
x cos
y sin
1 0
sin
cos
0
0
1
x
y
1
Scales:
x s x
y 0
1 0
0
sy
0
0
0
1
x
y
1
13
What of it?
We can represent any of our three transformations as a single
matrix.
No special cases when transforming a point matrix vector.
Composite transformations matrix matrix.
Composite transformations:
Rotate about an arbitrary point translate, rotate, translate
Scale about an arbitrary point translate, scale, translate
Change coordinate systems translate, rotate, scale
14
f
h
j ae bg
l ce dg
af bh i
cf dh k
f i
h k
j
l
a b ei fk
c d gi hk
j
l
aej bgj afl bhl
cej dgj cfl dhl
ej fl
gj hl
15
f ae bg
h ce dg
af bh
cf dh
a b ea fc
h c d ga hc
eb fd
a b e
c d g
e
g
gb hd
16
Order of operations
So, it does matter. Lets look at an example:
17
Useful compositions
Rotate about a pivot point:
T(pivot) R( ) T(pivot) P
18
Other transformations
Reflection:
x-axis
y-axis
1 0 0
0 1 0
0 0 1
1 0 0
0 1 0
0 0 1
19
Other transformations
Reflection:
origin
1 0 0
0 1 0
0 0 1
line x=y
0 1 0
1 0 0
0 0 1
20
Other transformations
Shear:
x-direction
1 shx
0 1
0 0
0
0
1
y-direction
1
sh
y
0
0 0
1 0
0 1
21
22
Matrix multiplication
So we can do a lot with one basic operation.
Wed better make this operation as fast as possible.
Lets start with the form of the matrix:
a b
M 1 d e
0 0
c
f
1
23
Matrix multiplication
Since we dont use the bottom row of the 2D transformation
matrix, we could have a special transform composition
operation:
a b
M 1 d e
0 0
a b
M 1 M 2 d e
0 0
c
f
1
c g
f j
1 0
g
M 2 j
0
h i
k l
0 1
h i ag bj ah bk
k l dg ej dh ek
0 1
0
0
ai bl c
di el f
1
24