Skip to main content

How Vectors Work: Dot Products, Cross Products, and Magnitudes Explained

Learn what vectors are, how to compute dot products, cross products, magnitudes, and angles between vectors — with step-by-step examples in 2D and 3D.

What Is a Vector?

A vector is a quantity that has both a magnitude (size) and a direction. A single number like “5 mph” is a scalar — it describes speed but not direction. “5 mph due north” is a vector — it describes both. In mathematics, a 2D vector is written as A = (Ax, Ay) and a 3D vector as A = (Ax, Ay, Az), where the components describe displacement along each coordinate axis.

Vectors appear everywhere in physics (force, velocity, acceleration), computer graphics (positions, normals, lighting), and engineering (stress tensors, electromagnetic fields). Mastering the core operations — addition, dot product, cross product, and magnitude — unlocks a wide range of applied problems.

Vector Addition and Subtraction

Adding two vectors places them tip-to-tail. The result is a new vector whose components are the sums of the corresponding components:

A + B = (Ax + Bx,  Ay + By,  Az + Bz)

Subtraction reverses the second vector before adding:

A − B = (Ax − Bx,  Ay − By,  Az − Bz)

Example: A = (1, 2) and B = (3, 4).

A + B = (1+3, 2+4) = (4, 6)
A − B = (1−3, 2−4) = (−2, −2)

Magnitude

The magnitude (or length) of a vector is its Euclidean distance from the origin:

|A| = √(Ax² + Ay² + Az²)

For 2D, drop the Az² term.

Example: |A| where A = (3, 4):

|A| = √(9 + 16) = √25 = 5

The (3, 4, 5) right triangle is a classic. A unit vector is any vector with magnitude 1; you normalize A by dividing each component by |A|.

Dot Product

The dot product of two vectors produces a scalar (a single number):

A · B = Ax·Bx + Ay·By + Az·Bz

It equals the product of the magnitudes times the cosine of the angle between them:

A · B = |A| × |B| × cos(θ)

Example: A = (1, 2), B = (3, 4):

A · B = 1×3 + 2×4 = 3 + 8 = 11

The dot product is zero when the vectors are perpendicular (cos 90° = 0). A positive dot product means the angle between the vectors is acute (< 90°); a negative dot product means the angle is obtuse (> 90°).

Worked Example

Inputs:

  • Vector A: (1, 2) — 2D
  • Vector B: (3, 4) — 2D
  • Operation: dot product

Calculation:

A · B = 1×3 + 2×4 = 3 + 8 = 11

Result: The dot product is 11.

The dot product is positive, confirming the angle between A and B is acute. Computing the angle: cos(θ) = 11 / (√5 × √25) = 11 / (2.236 × 5) = 11/11.18 ≈ 0.984, so θ ≈ arccos(0.984) ≈ 10.3°.

Angle Between Vectors

To find the angle between two vectors, rearrange the dot product identity:

θ = arccos(A · B / (|A| × |B|))

This gives an angle in the range [0°, 180°].

Cross Product (3D Only)

The cross product of two 3D vectors produces a new vector perpendicular to both. Its components are:

A × B = (Ay·Bz − Az·By,
         Az·Bx − Ax·Bz,
         Ax·By − Ay·Bx)

The magnitude of A × B equals the area of the parallelogram spanned by A and B:

|A × B| = |A| × |B| × sin(θ)

The cross product is only defined in 3D. In 2D problems, you can compute the z-component alone (called the perp-dot product or 2D cross product) as Ax·By − Ay·Bx, which gives the signed area of the parallelogram.

Practical Applications

Perpendicularity test: A · B = 0 means the vectors are orthogonal — useful in collision detection, surface normals, and machine learning feature engineering.

Lighting in 3D graphics: The intensity of light hitting a surface equals the dot product of the light direction and the surface normal. When the surface faces away from the light, the dot product is negative and the surface is in shadow.

Torque: τ = r × F (cross product of position vector and force vector) gives the torque vector in rotational mechanics.

Navigation: A ship’s velocity vector projected onto a compass bearing (dot product with a unit direction vector) gives the speed component in that direction.