CS430 Computer Graphics - Winona State University
Download
Report
Transcript CS430 Computer Graphics - Winona State University
CS430
Computer Graphics
Vectors
Part I
Chi-Cheng Lin, Winona State University
Topics
Why Vectors?
Vector 101
Coordinate Systems
Inner Product
Cross Product
2
Why Vectors?
Solving geometric problems easily
Describing objects in computer graphics
Projection
Ray Tracing
Representing coordinate system
Etc…
3
Sample Vector Problems
4
Vector 101
Definition
An object that has length and direction
BUT, no inherent location
Displacement in space, force, velocity
Representation
2D: (x, y)
3D: (x, y, z)
:
mD: (a1, a2, …, am)
5
Vector 101
Representation of vector and point
Vector: boldface lowercase letter, e.g., v, a, n
Point: Italic uppercase letter, e.g., A, B, P
Example
P = (1, 3) and Q = (4, 1), then
vector v = Q – P = (4-1, 1-3) = (3, -2)
y
P
v
v
Q
v
x
6
Basic Operations
If a=(ax, ay) and b=(bx, by) are vectors
Addition
a + b = (ax + bx, ay + by)
b
a+b
a
Parallelogram Rule
a+b
a
b
Displacement Rule
7
Basic Operations
Scaling
s a = (s ax, s ay), where s is a scalar
-a
a
1.2 a
Subtraction
a - b = a + (- b) = (ax - bx, ay - by)
b
b
-b
a
a-b
a
8
Linear Combination
Definition
The linear combination of m vectors v1, v2,
…, vm is a vector of the form
w = a1v1 + a2v2 + … + amvm , where
a1, a2, …, am are scalars
Affine combination
If a1 + a2 + … + am = 1
E.g., 3a + 2b – 4c ?
3a + b – 4c ?
For two vectors a and b,
affine combination v = (1 – t) a + t b
9
Linear Combination
Convex combination
If a1 + a2 + … + am = 1 AND
ai 0, for i = 1, …, m
It implies that 1 ai 0, for i = 1, …, m
(why?)
E.g., .3a + .7b ?
1.8a - .8b ?
10
Set of Convex Combination
Of two vectors v1 and v2:
v = (1 - a)v1 + a v2
v = v1 + a (v2 - v1)
As a varies from 0 to 1, v “moves” from
v1 to v2 along (v2 - v1)
v2
v
a (v2 - v1)
v1
11
Set of Convex Combination
Of three vectors v1 ,v2, and v3:
v = a1v1 + a2v2 + (1 - a1 - a2)v3
v2
v3
v
v1
12
Magnitude of Vectors
Magnitude (length, or size) of vector
w = (w1, w2, …, wm), denoted |w|,
|w| = w 12 w 22 w m2
E.g., w = (4, -2), |w| = ?
w = (1, -3, 2), |w| = ?
If w = B – A, |w| = distance between
points A and B
13
Unit Vector
Vector with unity length
Given a vector v, a unit vector having
the same direction of v, denoted vˆ , can
be obtained by normalization,
v
vˆ
v
(Are you sure |vˆ | = 1?)
14
Coordinate Systems
2D
Right-handed 3D
Left-handed 3D
y
y
z
z
Right-handed
x
x
Left-handed
15
Coordinate Systems
Standard unit vectors in 3D
i = (1, 0, 0), j = (0, 1, 0), and k = (0, 0, 1)
Any 3D vector (a, b, c) can be represented
by a i + b j + c k
y
y
j
j
k
i
x
z
i
x
k
z
Right-handed
Left-handed
16
Dot Product
Inner product
Definition
v = (v1, v2, …, vm) and w = (w1, w2, …, wm),
the dot product d = v • w
m
v iw i
i 1
E.g., a = (3, 4), b = (1, 6)
d = a • b = 3x1 + 4x6 = 27
Result of dot product is a scalar
17
Properties of Dot Product
Symmetry: a • b = b • a
Linearity: (a + c) • b = a • b + c • b
Homogeneity: (s a) • b = s (a • b)
|b|2 = b • b, i.e., |b| = b • b
18
Angle Between Two Vectors
Let = c - b, = ?
c
b
b = (|b|cosb, |b|sinb)
c
b
c = (|c|cos c, |c|sinc)
b • c = |b|cosb x |c|cosc + |b|sinb x |c|sinc
= |b||c|(cosb x cosc + sinb x sinc)
= |b||c|(cos(b - c))
= |b||c|(cos )
bc b c ˆ
cos = b c b c b cˆ
cos is the dot product of the normalized
vectors
19
Angle Between Two Vectors
< 90o, if b • c > 0
= 90o, if b • c = 0
> 90o, if b • c < 0
Definition
Vectors b and c are perpendicular
(orthogonal, or normal) if b • c = 0
20
2D Perpendicular Vector
Definition
Let a = (ax, ay) then a = (-ay, ax) is the
counterclockwise perpendicular to a
a • a = 0 ??
|a| = |a| ??
Perpendicular of a 3D vector?
Examples
a
a
a
-a
a
21
Vector Resolution
A vector can be resolved into 2 vectors
We are interested in resolving into 2
perpendicular vectors
Given a vector c and a vector v, we want to
resolve c into two vectors Kv and Mv
M=? K=?
v
c
Mv
Kv
c = Kv + Mv
v
22
Vector Resolution
c = Kv + Mv
c • v = Kv • v + Mv • v = Kv • v
c• v c • v
K
2
v• v
v
c • v = Kv • v + Mv • v = Mv • v
c•v
c•v
M
2
v•v
v
c
c•v
v
2
v
c•v
v
2
v
23
Distance from Point to Line
Distance d from point C to line through
point A in direction v = ?
d Mv
c•v
(C - A ) • v
v
2
v
c • v
v
2
v
v
c • v
v
c
v
Example:
C
Mv
Kv
A
v
C=(6,4) and line through (1,1) and (4,9)
d=?
24
Orthogonal Projection
Orthogonal projection of c onto v is
Kv
c•v
v
Example
2
C
v
v
c
Mv
Kv
A
v
c = (6, 4) and a =(1, 2)
the orthogonal projection of c onto a = ?
25
Applications of Projection - Reflection
Reflection
r = ?
m + e = a
e + (-m) = r
2m = a - r
r = a - 2m
n (known)
a (known)
r (unknown)
n
a
m
e
r
-m
e
26
Reflection
m is the orthogonal projection of a onto n
m
a•n
n
2
n n
n (a • ) (a • nˆ )nˆ
n n
ˆ )n
ˆ
r a - 2m a - 2(a •n
n
Example
a = (4, -2), n = (0, 3)
r=?
a
m
e
r
e
-m
27
Cross Product
Defined for 3D vectors
Definition
a = (ax, ay, az), b = (bx, by, bz), the cross
product of a and b is
a b = (ay bz - az by) i + (az bx - ax bz) j +
(ax by - ay bx) k
or
i
j
k
a b = ax
ay
az
(determinant)
bx
by
bz
28
Properties of Cross Product
ij=k
j k = i
k i = j
a b = - a b
a (b + c) = a b + a c
(s a) b = s (a b)
Why is it useful?
Given two 3D vectors, find a 3D vector
perpendicular to them
29
Geometrical Interpretation of
Cross Product
a b is perpendicular to both a and b
|a b|=|a||b|sin, where is the
angle between a and b that is less than
180o
ab
Area of parallelogram
= |a b|
a
b
30
Applications of Cross Product
Finding the normal of a plane
Given three points P1 , P2 , P3 that are not
collinear (do not lie in a in a straight line)
Find the normal n of the plane determined
by P1 , P2 , P3
y
Let a = P2 - P1 and
b = P3 - P1, then
n=ab
Example
P3
b
P1
P2
a
x
z
Find the normal to the plane passes
through (1,0,2), (2,3,0), and (1,2,4)
31