1. Beginning Direct3D Game Programming:
Mathematics 3
Vectors
jintaeks@gmail.com
Division of Digital Contents, DongSeo University.
March 2016
2. Vector
Although more abstract definitions are possible, we usually
restrict ourselves to vectors defined by n-tuples of real
numbers, where n is typically 2, 3, or 4.
An n-dimensional vector V can be written as
V=(v1,v2,…,vn)
2
3. Vector addition and scalar multiplication: a vector v (blue) is
added to another vector w (red, upper illustration).
Below, w is stretched by a factor of 2, yielding the sum v +
2w.
3
4. Vector space
A vector space (also called a linear space) is a collection of
objects called vectors, which may be added together
and multiplied ("scaled") by numbers, called scalars in this
context. Scalars are often taken to be real numbers.
4
5. First example: arrows in the plane
The first example of a vector space consists of arrows in a
fixed plane, starting at one fixed point. This is used in physics
to describe forces or velocities. Given any two such
arrows, v and w, the parallelogram spanned by these two
arrows contains one diagonal arrow that starts at the origin,
too. This new arrow is called the sum of the two arrows and is
denoted v + w.
5
6. Second example: ordered pairs of numbers
A second key example of a vector space is provided by pairs
of real numbers x and y. (The order of the
components x and y is significant, so such a pair is also called
an ordered pair.)
Such a pair is written as (x, y).
The sum of two such pairs:
(x1, y1) + (x2, y2) = (x1 + x2, y1 + y2)
The multiplication of a pair:
a(x, y) = (ax, ay).
6
8. Linear combination
In mathematics, a linear combination is
an expression constructed from a set of terms by multiplying
each term by a constant and adding the results (e.g. a linear
combination of x and y would be any expression of the
form ax+ by, where a and b are constants).
8
10. In the theory of vector spaces the concept of linear
dependence and linear independence of the vectors in a
subset of the vector space is central to the definition
of dimension.
A set of vectors is said to be linearly dependent if one of the
vectors in the set can be defined as a linear combination of
the other vectors. If no vector in the set can be written in this
way, then the vectors are said to be linearly independent.
10
11. Basis(linear algebra)
A set of vectors in a vector space V is called a basis, or a set
of basis vectors, if the vectors are linearly independent and
every vector in the vector space is a linear combination of this
set.
11
• The same vector can be represented in two different
bases (purple and red arrows).
12. A vector v in R2 (blue) expressed in terms of different bases:
using the standard basis of R2 v = xe1 + ye2 (black), and using
a different, non-orthogonal basis: v = f1 + f2 (red).
12
13. Practice: Write a KVector class.
class KVector {
public:
KVector(float x=0, float y=0, float z=0);
virtual ~KVector();
void Translate(float tx, float ty, float tz);
void Scale(float sx, float sy, float sz);
void RotateZ(float theta);
float m_x;
float m_y;
float m_z;
};//class KVector
13
We assume the origin is located at the center of client area.
Draw the x-axis with red line.
Draw the y-axis with green line.
Draw two vectors A(5,4), B(2,7) with black line.
Draw A+B with blue line.
14. Length
The magnitude of an n-dimensional vector V is a scalar
denoted by ||V|| and is given by the formula
The magnitude of a vector is also sometimes called the norm
or the length of a vector. A vector having a magnitude of
exactly one is said to have unit length, or may simply be
called a unit vector.
When V represents a three-dimensional point or direction,
above equation can be written as:
14
15. Unit vector
The normalized vector of a non-zero vector u is the unit
vector in the direction of u, i.e.,
Unit vectors may be used to represent the axes of a Cartesian
coordinate system. For instance, the unit vectors in the
direction of the x, y, and z axes of a three dimensional
Cartesian coordinate system are
15
16. Inner Product
The dot product of two vectors, also known as the scalar
product or inner product, is one of the most heavily used
operations in 3D graphics because it supplies a measure of
the difference between the directions in which the two vectors
point.
𝑃 · 𝑄 = 𝑖=1
𝑛
𝑃𝑖 𝑄𝑖
This definition states that the dot product of two vectors is
given by the sum of the products of each component. In
three dimensions, we have
P·Q=PxQx+PyQy+PzQz
16
17. Given two n-dimensional vectors P and Q, the dot product P
⋅Q satisfies the equation
P·Q=||P|| ||Q||cos(α)
where α is the planar angle between the lines connecting the
origin to the points represented by P and Q.
17
18. The sign of the dot product tells us whether two vectors lie
on the same side or on opposite sides of a plane.
18
19. The situation often arises in which we need to decompose a
vector P into components that are parallel and perpendicular
to another vector Q.
19
20. Practice: Extend the KVector class.
20
Add Length() function.
Add Normalize() function.
Add Dot() function.
Print the angle between A(5,4) and B(2,7).
class KVector {
public:
float Length() const;
void Normalize()
KVector Dot(const KVector3& rhs_) const;
};//class KVector
21. Matrix
In mathematics, a matrix (plural matrices) is
a rectangular array of numbers, symbols, or expressions,
arranged in rows and columns. The dimensions of below
matrix are 2 × 3 (read "two by three"), because there are two
rows and three columns.
21
22. Each element of a matrix is often denoted by a variable with
two subscripts. For instance, a2,1 represents the element at the
second row and first column of a matrix A.
22
23. Size
The size of a matrix is defined by the number of rows and
columns that it contains. A matrix with m rows and n columns
is called an m × n matrix or m-by-n matrix,
while m and n are called its dimensions.
23
24. Notation
Matrices are commonly written in box
brackets or parentheses:
The (1,3) entry of the following matrix A is 5 (also
denoted a13, a1,3, A[1,3] or A1,3):
24
25. Basic operations
There are a number of basic operations that can be applied to
modify matrices, called matrix addition, scalar
multiplication, transposition, matrix multiplication and row
operations.
25
26. Addition
The sum A+B of two m-by-n matrices A and B is calculated
entrywise:
(A + B)i,j = Ai,j+ Bi,j, where 1 ≤ i ≤ m and 1 ≤ j ≤ n.
26
27. Transposition
The transpose of an m-by-n matrix A is the n-by-m
matrix AT (also denoted Atr) formed by turning rows into
columns and vice versa:
(AT)i,j = Aj,i.
27
28. Scalar multiplication
The product cA of a number c (also called a scalar in the
parlance of abstract algebra) and a matrix A is computed by
multiplying every entry of A by c:
(cA)i,j = c · Ai,j.
This operation is called scalar multiplication, but its result is
not named “scalar product” to avoid confusion, since “scalar
product” is sometimes used as a synonym for “inner product”.
28
29. Determinant
In linear algebra, the determinant is a useful value that can
be computed from the elements of a square matrix. The
determinant of a matrix A is denoted det(A), det A, or |A|.
29
30. Cross Product
The cross product of two three-dimensional vectors, also
known as the vector product, returns a new vector that is
perpendicular to both of the vectors being multiplied
together.
30
• The cross-product in respect to a left-handed coordinate
system.
31. Cross Product
Used in a method for calculating a surface normal at a
particular point given two distinct tangent vectors.
P×Q=(PyQz-PzQy, PzQx-PxQz, PxQy-PyQx)
31
• The cross-product in respect to a left-handed coordinate
system.
32. A commonly used tool for remembering this formula is to
calculate cross products by evaluating the
pseudodeterminant.
where i, j, and k are unit vectors parallel to the x, y, and z
axes:
i=(1,0,0)
j=(0,1,0)
k=(0,0,1)
32
34. Geometrix meaning
The magnitude of the cross product can be interpreted as the
positive area of the parallelogram having a and b as sides:
34
35. Algebraic properties
If the cross product of two vectors is the zero vector
(i.e. a × b = 0), then either one or both of the inputs is the
zero vector, (a = 0 and/or b = 0) or else they are parallel or
antiparallel (a ∥ b) so that the sine of the angle between
them is zero (θ = 0° or θ = 180° and sinθ = 0).
The self cross product of a vector is the zero vector,
i.e., a × a = 0.
The cross product is anticommutative,
a×b=-(b×a)
distributive over addition,
a×(b+c)=(a×b)+(a×c)
and compatible with scalar multiplication so that
(ra)×b=a×(rb)=r(a×b)
35
36. Relation with dot product
The cross product and the dot product are related by:
36
37. A rotating body
In mathematics a rotating body is commonly represented by
a vector along the axis of rotation. The length of the vector
gives the speed of rotation and the direction of the axis gives
the direction of rotation according to the right-hand rule.
37