Homogeneous 4x4 matrices
Add a 4th coordinate:
P = [ x
y
z
1 ]
Now you can include translation in the matrix.
Translation matrix
T(dx, dy, dz) =
[ 1 0 0 dx
0 1 0 dy
0 0 1 dz
0 0 0 1 ]
Rotation in 4×4 form (example: Z)
Rz(θ) =
[ cos(θ) -sin(θ) 0 0
sin(θ) cos(θ) 0 0
0 0 1 0
0 0 0 1 ]
Rotate around arbitrary point (clean version)
Instead of manual translate/rotate/translate, combine matrices:
M = T(cx, cy, cz) * R * T(-cx, -cy, -cz)
P' = M * P