Tutorial 1
description
Transcript of Tutorial 1
Math for CS Tutorial 1 1
Tutorial 1
Course Outline
Homogeneous Coordinates
Math for CS Tutorial 1 2
Matrix Multiplication Rule
......
....
....
32
11
333231
232221
131211
333231
232221
131211
iii
iii
ba
ba
bbb
bbb
bbb
aaa
aaa
aaa
BA
Matrices make linear transformations of vectors
..323222121
313212111
3
2
1
333231
232221
131211
xaxaxa
xaxaxa
x
x
x
aaa
aaa
aaa
xA
Math for CS Tutorial 1 3
Translation, Scaling, Rotation of Vectors
22
11
2
1
2
1
dx
dx
d
d
x
xdx
2
1
2
1
22
11
0
0
x
x
S
S
xS
xSxS
2
1
12
21
cossin
sincos
sincos
sincos
x
x
xx
xxxR
Math for CS Tutorial 1 4
100
10
01
2
1
d
d
T dxdx
dx
x
x
d
d
xT
11100
10
01
22
11
2
1
2
1
Translation
Now, we can write the translation as the multiplication by specially designed matrix:
Translation in Homogeneous coordinates
1
2
1
x dxxT
1
3
2
1
2
1
100
110
101
Math for CS Tutorial 1 5
gdgd
gd
g
g
d
d
TT
100
10
01
100
10
01
100
10
01
22
11
2
1
2
1
21 Two translations
We can check that the matrix representing two sequential translations can be written as the multiplication of their matrices.
Sequential Translations in Homogeneous Coordinates
Math for CS Tutorial 1 6
Scaling in Homogeneous coordinates
100
00
00
2
1
S
S
S
11100
00
00
22
11
2
1
2
1
xS
xS
x
x
S
S
xS
Scaling
Scaling matrix looks similar to what it was for ordinary coordinates:
1
5.0
2
1
1
1
100
05.00
002
xS
What is the Matrix for Scaling 0.1x1 and 10x2 ?
Math for CS Tutorial 1 7
11100
00
00
1100
00
00
100
00
00
222
1
2
1
2
1 11
12
11
2
1
2
1
xSS
xSS
x
x
SS
SS
x
x
S
S
S
S
xSS AB
AB
AB
AB
A
A
B
B
AB
Two scalings
The matrix of two successful scalings is the multiplication of two scaling matrices:
Several Scalings in Homogeneous coordinates
What is the Matrix for Scaling 0.1x1 and 10x2 and then 20x1 and 0.1x2 ?
Math for CS Tutorial 1 8
1
cossin
sincos
1100
0cossin
0sincos
21
21
2
1
xx
xx
x
x
xR
Rotation
)(coscossinsinsincoscossin
cossinsincossinsincoscos
100
0cossin
0sincos
100
0cossin
0sincos
)()( 2112121212
1212121211
11
22
22
12
RRR
Two Rotations
Easy to check, that clock-wise rotation on angle θ is given by:
Two successful rotations can be represented by multiplication of their matrices:
)cos( 21 )sin( 21
Rotation in Homogeneous coordinates
Math for CS Tutorial 1 9
12
1
x
x
p
1
2
1
x
x
pHomogeneous coordinates scaled by a constant, represent the same point.
x2
x1
W2W3 W1
Scaling of Homogeneous coordinates
Math for CS Tutorial 1 10
Scaling of Homogeneous coordinates
1
2
1
p
2
4
2
2 pp
1.0
2.0
1.0
2
4
2
1
2
1
p
Math for CS Tutorial 1 11
100
10
01
100
0cossin
0sincos
100
10
01
)()( 2
1
2
1
p
p
p
p
xpTRpT
Rotation
How to write the rotation around a point ?
2
1
p
pp
Bring p back
Bring p to the origin
100
10
01
100
00
00
100
10
01
)()( 2
1
2
1
2
1
p
p
S
S
p
p
xpTSpT
ScalingBring p
backBring p to the origin
Bring the point p to the origin; make a rotation, bring it back:
… the same procedure for scaling:
Rotation around arbitrary point
Math for CS Tutorial 1 12
100
0cossin
0sincos
)(
R
1). Write down the matrix for: Rotation θ=90° around p=(2,5), translation (-2,2), scaling (x2) around p=(-1,1).
100
10
01
2
1
d
d
T
Translation
100
00
00
2
1
S
S
S
RotationScaling
( T(-1,1)·S(2,2)·T(1,-1) ) ·T(-2,2) ·( T(2,5) ·R(90) ·T(-2,-5) )
Example 1. Series of transformations
...))5,2()5,2((
100
110
101
100
020
002
100
110
101
TRT
100
301
710
100
120
102
...
Math for CS Tutorial 1 13
1
z
y
x
p
1000
100
010
001
z
y
x
d
d
d
T dxdz
dy
dx
z
y
x
d
d
d
xTz
y
x
z
y
x
111000
100
010
001Point Translation
1000
000
000
000
z
y
x
S
S
S
T pSzS
yS
xS
z
y
x
S
S
S
pTz
y
x
z
y
x
111000
000
000
000
Scaling
The translation and scaling are very similar in 3D:
Homogeneous coordinates in 3D
Math for CS Tutorial 1 14
The Rotation in 3D can be done around arbitrary axis. Euler angles representation.Any rotation is the composition of three basic rotation, a rotation around the axis x of an angle , a rotation around the axis y of an angle and a rotation around the angle z of an angle are called Euler anglesIn right hand coordinated these rotations are defined as follows
1000
0cossin0
0sincos0
0001
R
1000
0cos0sin
0010
0sin0cos
R
1000
0100
00cossin
00sincos
R
• Simple representation
• Order-dependent:
• Not suitable for animation, because the interpolation between the angles of rotation leads to false locations
RRRRRR ****
Rotation in 3D: Axis needed
Math for CS Tutorial 1 15
2). Rotation θ=90° around x followed by rotation θ=90° around y. find the axis of rotation.
R=R1·R2;If c – rotation axis, then:Rc=c;Solve v.r.t c;c=(a,a,-a,1)
3). Prove that rotation is not commutative: Rx(θ1)·Ry(θ2)≠ Ry(θ2) ·Rx(θ1)
1000
0010
0100
0001
)90(R
1000
0001
0010
0100
)90(R
1000
0100
0001
0010
RR
1000
0010
0001
0100
RR
Examples 2,3. Rotations in 3D
Math for CS Tutorial 1 16
The line equation in Euclidian Coordinates is:
The Euclidian point (x,y) in Homogeneous Coordinates can be written as p=(x,y,1) or
p=(αx, αy, α)
Therefore, denoting Euclidian line (1) by the homogeneous triple u=(a,b,c) we obtain,
that the point p lies on the line u iff:
For example, point p=(1,2,1) lies on the line y=x+1 which can be written by u=(1,-1,1)
)2(0),( 332211 pupupupu
)1(0 cybxa
Lines in Homogeneous Coordinates
)3(0112111),( pu
Math for CS Tutorial 1 17
Now, let us look for the interception point p=(x, y, w) of two lines u1=(a1,b1,c1) and
u2=(a2,b2,c2):
Form the first equation:
Substituting this into the second:
Taking convenient choice of scaling, in which
)1(0
0
222
111
wcybxa
wcybxa
Intersection of two lines 1/2
1
11
a
ybwcx
.
,)(
,0
1221
2112
21121221
221
112
baba
wcawcay
wcawcababay
wcyba
ybwca
1221 babaw
Math for CS Tutorial 1 18
We obtain
On the other hand, writing formally
We have showed, that the point p of the intersection of two lines u1 and u2 is described
by
Intersection of two lines 2/2
21211
2112112211
1
11 )()(bccb
a
cacabbabac
a
ybwcx
,1221 babaw 2112 cacay
],,[][][ 122121212121
222
11121 wyxbabacaacbccb
cba
cba
kji
uu
][],,[ 21 uuwyxp
Math for CS Tutorial 1 19
Now, let us look for the line u=(a, b, c) passing through two points p1=(x1,y1,w1) and
p2=(x2,y2,w2):
Similarly to the solution of the lines intersection, we obtain
The third point p3=(x3,y3,w3) lies on the line u if (p3,u)=0, which via definitions of
determinant can be written as
Due to duality of representation of lines and points in Homogeneous Coordinates, if the
three lines u1, u2 and u3 intersect in a single point, they satisfy
)1(0
0
222
111
wcybxa
wcybxa
)2(21 ppu
)3(0],,det[ 321 ppp
)4(0],,det[ 321 uuu
Three points on the line