determin.ant
01-vectors / 1.7

Module 1: Vectors

Cross Product

Where you'll see this: every surface normal in 3D graphics is a cross product. When a game engine shades a polygon, it computes the normal vector by crossing two edges — then uses the dot product with the light direction to get brightness. Physics engines use cross products for torque and angular momentum.

The dot product takes two vectors and gives a scalar. The cross product takes two vectors and gives a new vector — perpendicular to both.

The 2D version first

In 2D, the "cross product" of vectors a = [a₁, a₂] and b = [b₁, b₂] gives a scalar — the z-component of the 3D result:

a×b=a1b2a2b1a \times b = a_1 b_2 - a_2 b_1

This is exactly the determinant of the 2×2 matrix with a and b as rows. Its absolute value is the area of the parallelogram spanned by a and b. The sign tells you orientation: positive means b is counter-clockwise from a, negative means clockwise.

The 3D cross product

In 3D, with a = [a₁, a₂, a₃] and b = [b₁, b₂, b₃]:

a×b=[a2b3a3b2a3b1a1b3a1b2a2b1]\mathbf{a} \times \mathbf{b} = \begin{bmatrix} a_2 b_3 - a_3 b_2 \\ a_3 b_1 - a_1 b_3 \\ a_1 b_2 - a_2 b_1 \end{bmatrix}

The result is a vector perpendicular to both a and b. Its magnitude equals the area of the parallelogram: a×b=absinθ|\mathbf{a} \times \mathbf{b}| = |\mathbf{a}||\mathbf{b}|\sin\theta.

Right-hand rule: point your fingers along a, curl them toward b. Your thumb points in the direction of a × b. If b is clockwise from a, the cross product points into the screen; counter-clockwise means out of the screen.

Key properties

  • Anti-commutative: a×b=b×a\mathbf{a} \times \mathbf{b} = -\mathbf{b} \times \mathbf{a}
  • Parallel vectors: a×b=0\mathbf{a} \times \mathbf{b} = \mathbf{0} (zero area)
  • Always perpendicular: (a×b)a=0(\mathbf{a} \times \mathbf{b}) \cdot \mathbf{a} = 0

Try it

Drag the vectors. The shaded parallelogram's area equals |a × b|. The purple arrow shows which way the 3D cross product points (out of or into the screen). Make the vectors parallel — the area goes to zero.

In NumPy:
import numpy as np
a = np.array([3, 0, 0])
b = np.array([1, 2, 0])

cross = np.cross(a, b)
print(cross)         # [0, 0, 6] — points in z direction
print(np.linalg.norm(cross))  # 6.0 — area of parallelogram

# Surface normal for triangle with vertices p1, p2, p3:
normal = np.cross(p2 - p1, p3 - p1)
unit_normal = normal / np.linalg.norm(normal)
Linear IndependenceWhat is a Transformation?
-6-6-5-5-4-4-3-3-2-2-1-1112233445566+zab

a × b = a₁b₂ − a₂b₁ = 3·20·1 = 6

Parallelogram area = |a × b| = 6

Sign: positive (+z out of screen) — b is counter-clockwise from a

The shaded parallelogram has area = |a × b|. The purple arrow shows the 3D cross product direction (right-hand rule).