2D 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, 1])
Identity
 1  0  0
 0  1  0
 0  0  1
m = numpy.array([ [1, 0, 0],
                  [0, 1, 0],
                  [0, 0, 1] ])
Scaling
 cx  0   0
 0   cy  0
 0   0   1
m = numpy.array([ [cx, 0,  0],
                  [0,  cy, 0],
                  [0,  0,  1] ])
Translation
 1  0  tx
 0  1  ty
0  0  1
m = numpy.array([ [1, 0, tx],
                  [0, 1, ty],
                  [0, 0, 1 ] ])
Rotate About The
Z Axis
(origin 0,0)
cos(θ) -sin(θ) 0
sin(θ)  cos(θ) 0
  0       0    1
m = numpy.array([ [cos(θ), -sin(θ), 0],
                  [sin(θ),  cos(θ), 0],
                  [     0,       0, 1] ])

Note: In 2D there is no Z axis. However, you can think of an imaginary Z axis which is just the origin (0,0).

Code examples: convert degrees to radians, radians to degrees

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