Unit Vectors

Vectors of length 1 that represent pure direction.

What is a Unit Vector?

A unit vector is a vector with magnitude equal to 1. Unit vectors represent direction only, without any scaling.

\[|\hat{v}| = 1\]

Standard Unit Vectors

The standard unit vectors point along the coordinate axes:

\(\hat{i}\)
(1, 0, 0)
x-axis
\(\hat{j}\)
(0, 1, 0)
y-axis
\(\hat{k}\)
(0, 0, 1)
z-axis

Any vector can be written as a combination of unit vectors:

\[\vec{v} = (3, 4, 2) = 3\hat{i} + 4\hat{j} + 2\hat{k}\]

Creating Unit Vectors (Normalization)

To convert any non-zero vector to a unit vector, divide by its magnitude:

\[\hat{v} = \frac{\vec{v}}{|\vec{v}|}\]

Example: Normalize (3, 4)

|v| = √(9 + 16) = 5
û = (3/5, 4/5) = (0.6, 0.8)
Verify: √(0.36 + 0.64) = √1 = 1 ✓

Applications

  • Direction vectors: Represent direction without magnitude
  • Surface normals: Unit vectors perpendicular to surfaces
  • Basis vectors: Define coordinate systems
  • Cosine similarity: Normalized vectors for AI/ML

Code Examples

// JavaScript
function normalize(v) {
    const mag = Math.sqrt(v.reduce((s, x) => s + x*x, 0));
    return v.map(x => x / mag);
}

normalize([3, 4]); // [0.6, 0.8]
💡

Unit Vectors Explained Simply

Think of a unit vector as a "direction-only" pointer with a fixed length of exactly 1. It tells you which way to go, but nothing about how far.

The Compass Analogy

Imagine a compass needle. It always points north, but the needle itself doesn't tell you the distance to the North Pole. A unit vector works the same way—it's pure direction without any sense of distance or magnitude. Whether you're traveling 10 miles or 10,000 miles north, the compass needle (unit vector) stays the same.

What is Normalization?

Normalization is like resizing a photograph to fit a standard frame. You keep the same image (direction), but scale it to a specific size (length = 1). To normalize any vector, simply divide it by its own length. The result? A unit vector pointing in the exact same direction.

Why Length 1?

Having a length of exactly 1 makes math simple. Want a vector 5 units long pointing northeast? Take the northeast unit vector and multiply by 5. It's like having a recipe measured for one serving—scale up or down as needed.

Real-World Example

In video games, when a character moves diagonally, the game uses unit vectors to ensure consistent speed in all directions. Without normalization, moving diagonally would be faster than moving straight—unit vectors fix this by separating "which way" from "how fast."

Frequently Asked Questions

What is a unit vector?

A unit vector is a vector with a magnitude (length) of exactly 1. It represents pure direction without any information about distance or scale. Unit vectors are denoted with a hat symbol, like \(\hat{v}\), and are fundamental in physics, mathematics, and computer graphics for expressing directions.

How do you find a unit vector?

To find a unit vector, divide the original vector by its magnitude. For a vector \(\vec{v}\), the unit vector is \(\hat{v} = \frac{\vec{v}}{|\vec{v}|}\). For example, to find the unit vector of (3, 4): calculate the magnitude √(9+16) = 5, then divide each component by 5 to get (0.6, 0.8).

Why are unit vectors important?

Unit vectors are essential because they separate direction from magnitude, making calculations simpler and more intuitive. They're used in physics for representing forces and velocities, in graphics for lighting calculations and surface normals, in machine learning for cosine similarity, and in navigation for bearing directions.

What is vector normalization?

Normalization is the process of converting any non-zero vector into a unit vector. It scales the vector so its magnitude becomes 1 while preserving its direction. This is done by dividing each component of the vector by the vector's total magnitude. Normalization is a fundamental operation in many applications.

What are the standard unit vectors i, j, and k?

The standard unit vectors \(\hat{i}\), \(\hat{j}\), and \(\hat{k}\) point along the positive x, y, and z axes respectively. They are: \(\hat{i} = (1, 0, 0)\), \(\hat{j} = (0, 1, 0)\), and \(\hat{k} = (0, 0, 1)\). Any 3D vector can be expressed as a linear combination of these basis vectors.

Can a zero vector be normalized?

No, a zero vector (0, 0, 0) cannot be normalized because it has no direction and its magnitude is 0. Dividing by zero is undefined. In programming, attempting to normalize a zero vector typically results in an error or NaN values, so you should always check for zero magnitude before normalizing.

What is the difference between a vector and a unit vector?

A general vector has both magnitude and direction, where the magnitude can be any non-negative value. A unit vector is a special case where the magnitude is exactly 1. While a vector like (6, 8) has magnitude 10 and points in a certain direction, its corresponding unit vector (0.6, 0.8) points in the same direction but has magnitude 1.

How are unit vectors used in game development?

In game development, unit vectors are used for character movement direction (ensuring consistent speed in all directions), camera facing direction, lighting calculations with surface normals, projectile directions, AI pathfinding, and collision detection. They allow separating "which way" from "how fast" for cleaner code.

What is a normal vector vs a unit vector?

A normal vector is perpendicular (at 90°) to a surface or line, while a unit vector has magnitude 1. These concepts are independent but often combined: a "unit normal" is a vector that is both perpendicular to a surface AND has length 1. In 3D graphics, surface normals are typically stored as unit vectors for efficient lighting calculations.

How do you verify if a vector is a unit vector?

Calculate the magnitude of the vector by taking the square root of the sum of squared components. If the result equals 1 (or very close to 1 due to floating-point precision), it's a unit vector. For example, for (0.6, 0.8): √(0.36 + 0.64) = √1 = 1, confirming it's a unit vector.