Skip to content
3D Vectors & Operations
step 1/5

Reading — step 1 of 5

Read

~1 min read3D Math

3D Vectors & Operations

3D vectors are tuples (x, y, z).

Operations:

  • Add: a + b = (ax+bx, ay+by, az+bz).
  • Sub: a - b similarly.
  • Scalar mul: a * s = (axs, ays, az*s).
  • Length: |a| = √(ax² + ay² + az²).
  • Normalize: a / |a| → unit vector.
  • Dot: a · b = axbx + ayby + az*bz.
  • Cross: a × b = (aybz - azby, azbx - axbz, axby - aybx).
python

Cross product:

  • Result perpendicular to both inputs.
  • Right-hand rule for direction.
  • |a × b| = |a| * |b| * sin(angle).

Used heavily in graphics:

  • Surface normal: n = (b - a) × (c - a) for triangle abc.
  • Tangent space: cross of UV partial derivatives.
  • Camera basis: cross to construct orthonormal frame.
python

Normalize:

python

Distance between points: |a - b|.

Reflection: r = v - 2*(v·n)*n.

Refraction (Snell's law): more complex; uses indices of refraction.

Coordinate systems:

  • Right-handed: +X right, +Y up, +Z out of screen.
  • Left-handed: +Z into screen.
  • DirectX is left-handed; OpenGL is right-handed.
  • Conversion: flip Z.

NumPy or GLM library for production. Hand-coded for educational toys.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…