computer graphics and image processing geometry i · 2d: 2-tuples (x, y) with x and y coordinates...
TRANSCRIPT
Computer Graphics and Image Processing Geometry IPart 1 – Lecture 2
1
Today’s Outline Points, Vectors and Matrices The Dot Product The Cross Product
2
POINTS, VECTORSAND MATRICES
3
vyux
Points and Vectors Cartesian coordinate system:
orthogonal axes with numbers (coordinates)Origin: where all coordinates are zero (center)
Point: a position in space, e.g. AucklandGiven as pair (x,y) of coordinate values
Vector: a displacement / differencebetween two points (direction + length)
Example: Where is Hamilton? Point:
37.43S Latitude, 175.19E Longitude Vector:
120km to the south-south-westof Auckland
4
Representing Points and Vectors Points are represented as tuples
2D: 2-tuples (x, y) with x and y coordinates 3D: 3-tuples (x, y, z) with x, y, z coordinates
Vectors are also represented as tuples,but usually written as a column instead of a row
x componentand y component (in 3D also z component)
Position vector of a point: vector from origin to the point(often convenient to use vectors instead of points)
Our notation: Points are written in capital letters, e.g. P Vectors in small bold letters, e.g. position vector of P is p 5
yx
v
x
y
z
Right-handed 3Dcoordinate system
Operations on Points and VectorsVectors Add, subtract Scale (change length)
Points Subtracting one point from another gives a vector (displacement) Cannot add two points (Auckland + Hamilton = ???),
but can add and subtract their position vectors
6
a
b
a+b0.5 a
a
2 a
O
P
Q
P-Q=p-q
O
P
Q
p+q
Basic Operations on Vectors Addition
Represents the combined displacement Add corresponding components
Subtraction Subtract the corresponding components Same as addition of a negated vector,
i.e. one in opposite direction Scaling
Changing the length Defined such that v + v = 2v Multiply all components by the scalar
Magnitude of a vector Calculating its "length" or 2-norm
Normalization Scaling vector so that it has length 1 (unit vector) Scale by reciprocal of magnitude
1 1 1 1
2 2 2 2
u v u vu v u v
u v
1 1
2 2
u s u
s su s u
u
1 1 1 1
2 2 2 2
u v u vu v u v
u v
2 21 2 , u u s s u u u
ˆ uuu
u1
u2u
7
MatricesMatrix: several vectors stuck together mn matrix has m rows and n columns Like m row vectors or n column vectors
Operations Addition/Subtraction:
like adding/subtracting several vectors at the same time
Scaling: like scaling several vectors at the same time
8
11 12 13
21 22 23
r r rr r r
R
row
column
11 12 11 12 11 11 12 12
21 22 21 22 21 21 22 22
m m n n m n m nm m n n m n m n
M N
11 12
21 22
s m s ms
s m s m
M
Matrix MultiplicationMultiplying an l m matrix B and an m n matrix C
gives an l n matrix A with
“Rows times columns” with the products summed up
Elements of A are the dot products of the row vectors of B and column vectors of C
Can be used to transform several vectors simultaneously
9
11 12 11 12 11 11 12 21 11 12 12 22
21 22 21 22 21 11 22 21 21 12 22 22
b b c c b c b c b c b cb b c c b c b c b c b c
A B C
1 11
...m
ij i j im mj ik kjk
a b c b c b c
21
11
21
11Baa
cc
22
12
22
12Baa
cc
Identity and InverseIdentity matrix I: Neutral element of matrix
multiplication, i.e. for all M:I M = M I = M
Inverse matrix M-1 of a square matrix M (does not always exist):
M M-1 = M-1 M = I and (M-1) -1 = M
Inverse of a 2x2 matrix:
Exists only if m11 m22 – m12 m21 ≠ 010
111 12 22 12
21 22 21 1111 22 12 21
1m m m mm m m mm m m m
1001
I
The Transpose Operation TMake rows out of columns (or vice versa) Transpose of a row vector is a
column vector (and vice versa) For matrix M:
mij and mji are swappedfor all i=1..m, j=1..n
Rules:(MT)T=M(sM)T=s(MT)(M+N)T=MT+NT
(MN)T=NTMT
11
11 2
2
Tuu u
u
u u
11 2111 12 13
12 2221 22 23
13 23
T
m mm m m
m mm m m
m m
M M
THE DOT PRODUCT
12
)cos(vuvuvu T
The Dot Product •Takes two vectors u and v, the result is a scalar (a single number)(therefore also known as scalar product)
( is the angle between u and v)
Rules:a•b=b•a (Symmetry)(a+b)•c=a•c+b•c (Linearity)(sa)•b=s(a•b) (Homogeneity)|b|2= b•b
Example: |a - b|2 = (a - b) • (a - b) = a • a - 2a • b + b • b13
vuvu T
2211
2
1
2
1 vuvuvv
uu
)cos(vu
u
v
The Angle between Two VectorsMost important application of dot product:find angle between two vectors (or two intersecting lines)
Two non-zero vectors b and c with common start point are:less than 90o apart if b•c>0exactly 90o apart if b•c=0 [b and c are orthogonal (perpendicular)]more than 90o apart if b•c<0
c b
b
c
x
y
cos
cos
sinsincoscoshence
sincos
,sincos
cb
cb
cbcb
cc
bb
bc
cbcb
c
c
b
b
cb
cb
cos
14
Orthogonal Projection of a VectorProjecting a vector b onto another vector a: L is a line through A with direction a b is the vector from A to BGiven: a and bWanted: ba (orthogonal projection of b onto a)Solution:1. Length of ba: because of def. •
2. Vector ba: because
15
ababba
)cos(
aaaba
aa
ababa
)cos(baba
2aaa
c
a
b
abL
B
A
Distance from a Line to a Point L is a line through A with direction a b is the vector from A to B
Given: a and bWanted: Solution:
16
c
aaababbbc a
c
a
b
abL
B
A
THE CROSS PRODUCT
17
nbaba )sin(
1221
3113
2332
babababababa
The Cross Product Takes two 3D vectors u and v, the result is a 3D vector(therefore also known as vector product)
is the angle between a and b n is unit normal vector (|n|=1) orthogonal to a and b Hard to remember?Rules:
(a+b)c = ac + bc (Linearity)(sa)b = s(ab) (Homogeneity)(no symmetry)
18
nbaba )sin(
1221
3113
2332
babababababa
sin
Properties of the Cross Product1. a b is a vector perpendicular/orthogonal to both a and b2. Direction of a b is given by "right-hand rule"3. a b = – b a4. |a b| is area of parallelogram defined by a and b5. Area of triangle defined by a and b is 0.5 * |a b|
19
nbaba )sin(
a
b
a
b
c
SUMMARY
20
Summary1. Vectors:
addition, subtraction, scaling, magnitude, normalization2. Matrices:
addition, subtraction, scaling, multiplication3. Dot product:
4. Cross product:
References: Vectors: Hill, Chapter 4.2 Dot Product: Hill, Chapter 4.3 Cross Product: Hill, Chapter 4.4 21
)cos(vuvuvu T
nbaba )sin(
1221
3113
2332
babababababa
Quiz
1. Calculate: a+b, |b| a, Ma, MN, ab, ab2. What can you tell about the angle between a and b?3. What is the projection of b onto a?4. What is the distance between the point given by b and the line
going through theorigin along a?
22
321
a
212
b
203012101
M
131111010
N