Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Vectors

💡 TABLE OF CONTENTS
Introduction to Vectors
Magnitude and Direction of a Vector
Zero Vector
Unit Vector
Operations on Vectors
Addition of Vectors
Subtractions of Vectors
Normalization of a Vector
Scalar (or Dot) Product Of Two Vectors
Things to remember -
Vector (or Cross) Product of Two Vectors
Useful Properties of Unit Vectors
More Resources
Stay in Touch
Could you do me a favour?

If you want to be a 3D programmer, vectors should be on top of your priority


list. A good 3D programmer knows how to manipulate vectors.

Want this pdf as a Notion Template? Get the template now and customize it
as much as you want. Here is the link -
https://knightcube.gumroad.com/l/knightcube-notes-vectors-pdf

Introduction to Vectors

💡 Vectors are defined by n-tuples of real numbers, where n equals 2,3 or 4. Simply put —
n-vector is a list of n numbers. Programmers can think of it as an array.

Vectors can be used to store locations but locations are not vectors. For instance, you
can add 2 vectors but it does not make sense to add 2 locations.

An n dimensional vector V can be written as 👇


V = ⟨V1 , V2 , ....Vn ⟩ (1)

Here, V1 , V2 , V3 , … Vn are called the components of the vector V.

Sold to
Vectors 1
pariharr06@gmail.com
Note that there is no arrow on top of the components V1 , V2 , V3 . This is because the components
of a vector are scalar quantities.

Likewise, for a three dimensional vector P , its components would be written as Px , Py , Pz .

Therefore,

P = ⟨Px , Py , Pz ⟩ (2)

The same can be represented as a matrix having a single column and n rows like so 👇
⎡ V1 ⎤
V2
.
V = (3)
.
.
⎣Vn ⎦

So equation (1.2) above can be rewritten in the matrix form as follows 👇


⎡Px ⎤
P = Py (4)
⎣ Pz ⎦

Magnitude and Direction of a Vector


From a geometric point of view, a vector is a line segment that has a magnitude and a direction.

Magnitude - is the length of the vector.

Direction - describes the way the vector is pointing in space

💡 Direction and orientation are not same.

The magnitude of an n-dimensional vector V is a scalar denoted by ∣ V ∣ and is given by the


formula

n
∣V ∣ = ∑ Vi 2 (5)
i=1

Vectors 2
So for a 3 dimensional vector 👇
P the magnitude will be calculated as follows

∣P ∣ = Px 2 + Py 2 + Pz 2 (6)

Zero Vector
A vector with the magnitude of 0 is called a zero vector. That is,

∣V ∣ = 0

Unit Vector
A vector with the magnitude of 1 is called a unit vector. That is,

∣V ∣ = 1

Operations on Vectors
Addition of Vectors
To add two vectors, we simply add the corresponding components like so -

⎡ P1 ⎤ ⎡ Q1 ⎤ ⎡ P1 + Q1 ⎤
P2 Q2 P2 + Q2
. . .
. + . = . (7)
. . .
+ Qn−1
⎣ Pn ⎦ ⎣ Qn ⎦ ⎣ Pn + Qn ⎦
Pn−1 Qn−1 Pn−1

Subtractions of Vectors
Subtracting is same as adding the negative, i.e P − Q = P + (−Q)
Therefore,

⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎛ ⎡ ⎤⎞ ⎡ ⎤
Vectors 3
⎡ P1 ⎤ ⎡ Q1 ⎤ ⎡ P1 ⎤ ⎛ ⎡ Q1 ⎤⎞ ⎡ P1 − Q1 ⎤
P2 Q2 P2 Q2 P2 − Q2
. . . . .
. − . = . + − . = . (8)
. . . . .
− Qn−1
⎣ Pn ⎦ ⎣ Qn ⎦ ⎣ Pn ⎦ ⎝ ⎣ Qn ⎦⎠ ⎣ Pn − Qn ⎦
Pn−1 Qn−1 Pn−1 Qn−1 Pn−1

Things to remember

1. A vector cannot be added or subtracted with a scalar or a vector of a different dimension

2. Vector addition is commutative, but vector subtraction is not. This means that
P + Q = Q + P but P − Q =
 P − Q . Rather P − Q = −( Q − P )

Normalization of a Vector
Often times, you will face a situation where you need to know the direction in which a 3D object is
facing in your game or 3D world space. Note that we are concerned only with the direction and
not the magnitude. This is when you should think of normalization immediately.

In order to normalize a non zero vector, we simply divide the vector by its magnitude. Like this👇
V
V norm = (9)
∣V ∣

Here V is not a zero vector, i.e ∣ V ∣ =


0

💡 The zero vector cannot be normalized. Mathematically it is not allowed as it would


result in division by zero.

Scalar (or Dot) Product Of Two Vectors


The scalar (or dot) product of two non-zero vectors is heavily used in 3D graphics because it
provides the difference between the directions in which the 2 vectors point. It can be denoted by
P . Q (read as P dot Q ) and can be defined as,

P . Q = ∣ P ∣.∣ Q ∣ cos θ (10)

where θ (0 ≤ θ ≤ π) is the angle between P and Q .

The dot product of 2 n-dimensional vectors P and Q , is given by the formula,

Vectors 4
n
P . Q = ∑ Pi Qi (11)
i=1

Equation 1.9 means that the dot product of 2 vectors is given by the sum of the products of each
component. Therefore in 3 dimensions, we have 👇
⟹ P . Q = Px Qx + Py Qy + Pz Qz (12)

Generalizing eqn 1.12 for n components we get

⎡ P1 ⎤ ⎡ Q1 ⎤
P2 Q2
P3 Q3
. .
. = P1 Q1 + P2 Q2 + ⋯ + Pn−1 Qn−1 + Pn Qn (13)
. .
. .

⎣ Pn ⎦ ⎣ Qn ⎦
Pn−1 Qn−1

Things to remember -
1. The dot product of 2 vectors is a scalar quantity.

2. If P . Q = 0 i.e if ∣ P ∣.∣ Q ∣ cos θ = 0, then either ∣ P ∣ = 0 or ∣ Q ∣ = 0 or cos θ = 0. This


means that either (or both) of the vectors is a zero vector or else they are perpendicular to
each other i.e P ⊥ Q . Thus P . Q = 0 iff

a. P is a zero vector

b. Q is a zero vector

c. P ⊥Q

💡 Vectors whose dot product yields zero are called orthogonal vectors.

2 2
3. The square of a vector is equal to the square of its modulus i.e ( P ) = ∣P ∣

Vector (or Cross) Product of Two Vectors


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. This property is

Vectors 5
used in computer graphics to calculate a surface normal at a particular point given 2 distinct
tangent vectors. It is denoted as P × Q (read as P vector “cross” Q vector).

Given two 3D vectors P and Q , the cross product P × Q satisfies the following equation 👇
∣ P × Q ∣ = ∣P ∣ ∣Q∣ sin α (14)

where α is the planar angle between the lines connecting the origin to the points represented by
P and Q .

It’s calculated using the following formula 👇


P × Q = ⟨Py Qz − Pz Qy , Pz Qx − Px Qz , Px Qy − Py Qx (15)

An easier way to remember this formula is by evaluating this pseudodeteminant 👇


∣ i j k ∣
P × Q = Px Py Pz (16)
∣Qx Qy Qz ∣

where i, j and k (read as i “cap”, j “cap” and k “cap”) are unit vectors parallel to the x, y and z
axes.

∣ i j k∣
Px Py Pz = i(Py Qz − Pz Qy ) − j (Px Qz − Pz Qx ) + k (Px Qy − Py Qx )
Q
∣ x Qy Qz ∣

Useful Properties of Unit Vectors


1. i×j =k
2. j ×k =i
3. k×i = j
4. j × i = −k
5. k × j = −i
6. i × k = −j

For two scalars a and b, and any three 3D vectors P , Q and R , the following properties hold 👇

Vectors 6
1. Q × P = −( P × Q )

2. (a P ) × Q = a ( P × Q )

3. P × (Q + R ) = P × Q + P × R

4. P ×P =0

5. (P × Q) . R = ( R × P ) . Q = (Q × R ) . P
2
6. P × (Q × P ) = P × Q × P = P Q − (P .Q) P

More Resources
100+ AR/VR Resources Pack - Get here

💡 My 100+ AR/VR Resources Pack has got over 180+ downloads from more than
30+ countries all over the world. Save yourself 1000+ hours of research on AR/VR.

100+ AR/VR Resources Pack


A curated list of 100+ AR/VR Resources.Save thousands of
hours on AR/VR Research 🤩 I have compiled these
resources for all those who want to learn AR/VR, join AR/VR
https://knightcube.gumroad.com/l/arvr-resources

Introduction to UX Design for Augmented Reality Experiences - Get here

💡 My first ebook 🎉
where I talk about some of the design principles behind creating
Augmented Reality experiences. You can get it for 40% off. Use the code -
“supporter” at checkout.

Introduction to UX Design for Augmented Reality Experiences Ebook


A beginner's guide to designing Augmented Reality experiences.Learn the
design fundamentals of creating any Augmented Reality experience.
Beginner-friendly tips collected from global tech conferences, articles, books,
https://knightcube.gumroad.com/l/ux-for-ar

Vectors 7
FREE AR/VR Project Case Studies Checklist - Get here

💡 Get this free checklist where I deep dive into writing case studies for your AR/VR
projects 😉
How to write AR/VR Project Case Studies? (checklist - Notion)
Do you find writing case studies for your AR/VR projects tedious or
don't know how to write one?Then you will find this FREE checklist
helpful. After talking to a few recruiters in the AR/VR industry, I got to
https://knightcube.gumroad.com/l/arvr-project-case-studies

Stay in Touch
Send me a 👋 on Twitter!
Connect with me on LinkedIn
Watch my videos on YouTube 🎥 - I talk about Three.js, AR/VR, Blender and 3D stuff. 🎥
Could you do me a favour?
Could you please give a 5 ⭐ rating on Gumroad? Click here to do so. I want to continue
creating more content like this for 3D enthusiasts like you.

Vectors 8

You might also like