Module 1: Vectors
The dot product takes two vectors and gives a scalar. The cross product takes two vectors and gives a new vector — perpendicular to both.
In 2D, the "cross product" of vectors a = [a₁, a₂] and b = [b₁, b₂] gives a scalar — the z-component of the 3D result:
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.
In 3D, with a = [a₁, a₂, a₃] and b = [b₁, b₂, b₃]:
The result is a vector perpendicular to both a and b. Its magnitude equals the area of the parallelogram: ∣a×b∣=∣a∣∣b∣sinθ.
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.
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)a × b = a₁b₂ − a₂b₁ = 3·2 − 0·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).