Math Vector- Complete Guide to Vector Operations

What Is a Vector, Exactly?

A vector is a quantity with magnitude and direction. That's it. Unlike scalars, which are just numbers, vectors point somewhere in space.

Think of it this way: "5 miles" is a scalar. "5 miles north" is a vector. The direction matters.

Vectors show up everywhere in physics, engineering, computer graphics, machine learning, and game development. If you're working with spatial data, you need vectors.

How Vectors Are Written

Most textbooks write vectors with arrows on top: →v. In programming, you'll see them as arrays or tuples.

2D vector: v = (3, 4)

3D vector: v = (1, -2, 5)

The numbers inside are called components. Each component represents the vector's length along that axis.

Basic Vector Operations

Vector Addition

Add the components together. That's it.

(2, 3) + (4, 1) = (6, 4)

Visually, you're chaining vectors tip-to-tail. The result is the vector from the start of the first to the end of the last.

Vector Subtraction

Subtract each component. Order matters.

(5, 7) - (2, 3) = (3, 4)

Subtraction gives you the vector pointing from one point to another. Useful for calculating distances and directions.

Scalar Multiplication

Multiply each component by the scalar. This stretches or shrinks the vector.

3 × (2, 4) = (6, 12)

A negative scalar flips the direction.

-2 × (1, 3) = (-2, -6)

Magnitude (Length) of a Vector

The magnitude is how long the vector is. You calculate it with the Pythagorean theorem.

For v = (a, b): |v| = √(a² + b²)

For v = (a, b, c): |v| = √(a² + b² + c²)

Example: |(3, 4)| = √(9 + 16) = √25 = 5

Magnitude is always positive or zero. A zero vector means no movement.

Dot Product

The dot product multiplies vectors and gives you a scalar. That's why it's also called the scalar product.

Formula: v · w = a₁a₂ + b₁b₂

Example: (1, 2) · (3, 4) = 1×3 + 2×4 = 3 + 8 = 11

What the Dot Product Tells You

You can also calculate the dot product using magnitudes and the angle between vectors:

v · w = |v| |w| cos(θ)

This is useful when you know the angle but not the components.

Cross Product

The cross product only works in 3D. It gives you a new vector perpendicular to both input vectors.

Formula: v × w = (a₂b₃ - a₃b₂, a₃b₁ - a₁b₃, a₁b₂ - a₂b₁)

Example: (1, 2, 3) × (4, 5, 6)

= (2×6 - 3×5, 3×4 - 1×6, 1×5 - 2×4)

= (12-15, 12-6, 5-8)

= (-3, 6, -3)

Cross Product Applications

The magnitude |v × w| = |v| |w| sin(θ) gives you the area of the parallelogram formed by both vectors.

Unit Vectors

A unit vector has a magnitude of exactly 1. You get one by dividing a vector by its magnitude.

For v = (3, 4): v̂ = (3/5, 4/5) = (0.6, 0.8)

Standard unit vectors in 3D are î = (1, 0, 0), ĵ = (0, 1, 0), and k̂ = (0, 0, 1).

Unit vectors are useful for representing direction without magnitude.

Vector Normalization

Normalization converts any vector to a unit vector pointing in the same direction. Divide each component by the magnitude.

This is essential in lighting calculations, physics simulations, and anywhere you need pure direction.

Vector Comparison Table

Operation Result Type Formula Use Case
Addition Vector (a₁+b₁, a₂+b₂) Combining forces, movements
Subtraction Vector (a₁-b₁, a₂-b₂) Finding displacement
Dot Product Scalar a₁b₁ + a₂b₂ Projection, angle detection
Cross Product Vector (3D) See formula above Surface normals, torque
Magnitude Scalar √(a₁² + a₂²) Distance calculations
Normalization Unit Vector v / |v| Direction-only operations

Common Mistakes to Avoid

Getting Started: Vector Calculations

Here's how to perform basic vector operations in Python:

import math

def add(v1, v2):
    return (v1[0]+v2[0], v1[1]+v2[1])

def dot(v1, v2):
    return v1[0]*v2[0] + v1[1]*v2[1]

def magnitude(v):
    return math.sqrt(v[0]**2 + v[1]**2)

def normalize(v):
    mag = magnitude(v)
    return (v[0]/mag, v[1]/mag)

Most math libraries (NumPy, Unity, Unreal) have these built-in. Learn the manual calculations first so you understand what the functions are doing.

Where Vectors Are Used

Every field has its own conventions, but the math stays the same.

Quick Reference

Bookmark this page. You'll be coming back to it.