3D Transformation Matrix

Angle θ is in radians. Pi radians equal 180 degrees (2π rad = 360°).

DescriptionTransformation
Matrix
numpy array
Point Coordinates
xyz = numpy.array([x, y, z, 1])
Identity
 1  0  0  0
 0  1  0  0
 0  0  1  0
 0  0  0  1
m = numpy.array([ [1, 0, 0, 0],
                  [0, 1, 0, 0],
                  [0, 0, 1, 0],
                  [0, 0, 0, 1] ])
Scaling
cx  0   0  0
0   cy  0  0
0   0   cz 0
0   0   0  1
m = numpy.array([ [cx, 0,  0,  0],
                  [0,  cy, 0,  0],
                  [0,  0,  cz, 0],
                  [0,  0,  0,  1] ])
Translation
 1  0  0  tx
 0  1  0  ty
 0  0  1  tz
0  0  0  1
m = numpy.array([ [1, 0, 0, tx],
                  [0, 1, 0, ty],
                  [0, 0, 1, tz],
                  [0, 0, 0, 1] ])
Rotate About The
Z Axis
cos(θ) -sin(θ) 0  0
sin(θ)  cos(θ) 0  0
  0       0    1  0
  0       0    0  1
m = numpy.array([ [cos(θ), -sin(θ), 0, 0],
                  [sin(θ),  cos(θ), 0, 0],
                  [     0,       0, 1, 0],
                  [     0,       0, 0, 1] ])
Rotate About The
Y Axis
 cos(θ)  0  sin(θ) 0
   0     1    0    0
-sin(θ)  0  cos(θ) 0
   0     0    0    1
m = numpy.array([ [ cos(θ), 0, sin(θ), 0],
                  [      0, 1,      0, 0],
                  [-sin(θ), 0, cos(θ), 0],
                  [      0, 0,      0, 1] ])
Rotate About The
X Axis
1   0       0    0
0 cos(θ) -sin(θ) 0
0 sin(θ)  cos(θ) 0
0   0       0    1
m = numpy.array([ [1,      0,       0, 0],
                  [0, cos(θ), -sin(θ), 0],
                  [0, sin(θ),  cos(θ), 0],
                  [0       0,       0, 1] ])

Code examples: convert degrees to radians, radians to degrees

import numpy as np
rad = np.deg2rad(deg)
deg = np.rad2deg(rad)