Skip to content

Vectors in 2D and 3D

In this lesson you’ll learn the fundamentals of vectors, the building blocks of linear algebra. You’ll see how vectors represent direction and magnitude, and how they behave in both 2D and 3D space.

A vector is a quantity that has both magnitude (length) and direction.

  • In 2D: v=a,b\mathbf{v} = \langle a, b \rangle or v=ai+bj\mathbf{v} = a\mathbf{i} + b\mathbf{j}
  • In 3D: v=a,b,c\mathbf{v} = \langle a, b, c \rangle or v=ai+bj+ck\mathbf{v} = a\mathbf{i} + b\mathbf{j} + c\mathbf{k}

Here, aa, bb, and cc are called the components of the vector.

Different textbooks and fields use different notation for vectors. Here’s a quick guide so you’re never caught off guard:

  • Bold lowercase letters like v\mathbf{v} or u\mathbf{u} are vectors (common in textbooks and on this site)
  • An arrow on top like v\vec{v} or u\vec{u} also means vector (common in handwriting and physics)
  • Both mean the same thing: v=v\mathbf{v} = \vec{v}
  • Bold uppercase letters like A\mathbf{A} or M\mathbf{M} usually represent matrices (grids of numbers), which we’ll cover soon
  • Plain italic letters like aa, bb, kk are scalars (regular numbers)

On this site we’ll mostly use the bold notation (v\mathbf{v}), but if you see v\vec{v} in another resource, it’s the same idea.

  • Vectors are usually drawn as arrows.
  • The tail is at the starting point, and the head points in the direction of the vector.
  • The length of the arrow represents the magnitude.
x y 1 2 3 4 5 1 2 3 4 v = ⟨3, 4⟩ w = ⟨5, 2⟩ v̂ (unit) 3 4 ||v|| = 5 v = ⟨3, 4⟩ — a vector with magnitude 5 w = ⟨5, 2⟩ — a second vector for comparison v̂ — the unit vector of v (same direction, length 1)

The magnitude (or norm) of a vector v=a,b\mathbf{v} = \langle a, b \rangle is:

v=a2+b2\lVert \mathbf{v} \rVert = \sqrt{a^2 + b^2}

In 3D:

v=a2+b2+c2\lVert \mathbf{v} \rVert = \sqrt{a^2 + b^2 + c^2}

Example 1: Basic Vector

Draw the vector v=3,4\mathbf{v} = \langle 3, 4 \rangle in 2D.

Magnitude: v=32+42=9+16=25=5\lVert \mathbf{v} \rVert = \sqrt{3^2 + 4^2} = \sqrt{9 + 16} = \sqrt{25} = 5

x y 1 2 3 4 1 2 3 4 3 4 ||v|| = 5 v = ⟨3, 4⟩

Example 2: 3D Vector

Let w=1,2,2\mathbf{w} = \langle 1, 2, 2 \rangle.

Magnitude: w=1+4+4=9=3\lVert \mathbf{w} \rVert = \sqrt{1 + 4 + 4} = \sqrt{9} = 3

Example 3: Unit Vector

A unit vector has magnitude 1. To make v=3,4\mathbf{v} = \langle 3, 4 \rangle a unit vector, divide by its magnitude:

v^=35,45\hat{\mathbf{v}} = \left\langle \frac{3}{5}, \frac{4}{5} \right\rangle

Vectors are everywhere in game development:

  • Position vectors tell you where an object is.
  • Velocity vectors tell you how fast and in what direction it’s moving.
  • Force vectors (gravity, thrust, wind) are added together to determine movement.

Example: In a 3D game, the direction from your character to an enemy is a vector. The speed at which you’re moving is another vector. Adding them together helps the physics engine calculate realistic motion.

A vector has both:
The magnitude of the vector $\langle 3, 4 \rangle$ is:
In game development, velocity is represented as:
A unit vector has magnitude:
The vector $\langle 0, 0, 5 \rangle$ points: