Skip to content
Matrices & Transformations
step 1/5

Reading — step 1 of 5

Read

~2 min read3D Math

Matrices & Transformations

A 4×4 matrix encodes a 3D transformation: translate, rotate, scale, shear.

We use 4×4 (not 3×3) to combine all transforms uniformly via homogeneous coordinates.

A point (x, y, z) becomes (x, y, z, 1). A vector becomes (x, y, z, 0). Matrix multiply transforms.

Identity:

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

Translation by (tx, ty, tz):

1 0 0 tx
0 1 0 ty
0 0 1 tz
0 0 0 1

Scale by (sx, sy, sz):

sx 0  0  0
0  sy 0  0
0  0  sz 0
0  0  0  1

Rotation around X axis by θ:

1   0     0    0
0   cos -sin   0
0   sin  cos   0
0   0    0     1

Around Y, Z: similar.

Matrix multiply combines transforms:

M_combined = M_translate @ M_rotate @ M_scale

Apply: M @ point. Result is transformed point.

Matrix multiplication is non-commutative: order matters!

python

Common matrices used in pipeline:

  • Model: object → world space.
  • View: world → camera space.
  • Projection: camera → screen space.

Combined: P × V × M. Apply once per vertex.

Inverse:

  • M.inverse(): undoes the transform.
  • For pure rotation: M.transpose() = M.inverse() (orthonormal).
  • For combinations: explicit inverse computation.

Numpy makes this easier:

python

OpenGL stored matrices column-major historically. Modern shaders use column-major. Math is the same; layout differs.

Discussion

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

Sign in to post a comment or reply.

Loading…