Concept: Cross Product


Definition

  • Result is a vector perpendicular to both a and b
  • Magnitude: |a × b| = |a| * |b| * sin(θ)
  • Direction: right-hand rule (curl fingers from a to b, thumb points in result direction)

Key Properties

  • Anti-commutative: a × b = -(b × a) — ORDER MATTERS
  • a × a = (0, 0, 0) — cross product with itself is zero
  • |a × b| = area of parallelogram formed by a and b
  • If a × b = 0, vectors are parallel (or one is zero)

Uses in Path Tracing

  • Building orthonormal basis (TBN matrix)
    • Given normal N, need tangent T and bitangent B
    • T = normalize(cross(N, up)) where up = (0,1,0) (or (1,0,0) if N is near up)
    • B = cross(N, T) — already unit length if N and T are unit
    • Used to transform sampled directions from tangent space to world space
  • Triangle normal computation
    • Given vertices v0, v1, v2:
    • Winding order determines which side is “front”
  • Möller–Trumbore intersection
    • det = dot(edge1, h) — used to detect parallel ray
    • q = cross(s, edge1) — used to compute barycentric v

GLSL

  • Only defined for vec3 (not vec2 or vec4)

Degenerate Cases

  • If N is nearly parallel to up = (0,1,0):