2D Matrix Transformations
1. Translation
Translation moves each point of a matrix by a fixed distance along the x-axis and/or y-axis.
This operation shifts the matrix without changing its orientation or shape.
Translation Matrix:
[ x_new ] = [ 1 0 tx ] [ x ]
[ y_new ] = [ 0 1 ty ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Example: Translating a point (3, 4) by 2 units along the x-axis and 3 units along the y-axis:
[ x_new ] = [ 1 0 2 ] [ 3 ] = [ 5 ]
[ y_new ] = [ 0 1 3 ] [ 4 ] = [ 7 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
The point (3, 4) is shifted to (5, 7).
2. Scaling
Scaling changes the size of the matrix by multiplying the x and y coordinates by scaling
factors. This stretches or compresses the matrix, keeping the origin fixed unless otherwise
translated.
Scaling Matrix:
[ x_new ] = [ sx 0 0 ] [ x ]
[ y_new ] = [ 0 sy 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Example: Scaling a point (2, 3) by a factor of 2 in the x-axis and 3 in the y-axis:
[ x_new ] = [ 2 0 0 ] [ 2 ] = [ 4 ]
[ y_new ] = [ 0 3 0 ] [ 3 ] = [ 9 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
The point (2, 3) is scaled to (4, 9), stretching it along both axes.
3. Rotation
Rotation rotates a matrix around the origin by a specific angle θ (in radians). Rotation is
based on trigonometric functions (sine and cosine).
Rotation Matrix:
[ x_new ] = [ cos(θ) -sin(θ) 0 ] [ x ]
[ y_new ] = [ sin(θ) cos(θ) 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Example: Rotating a point (1, 0) by 90° counterclockwise (θ = 90° = π/2 radians):
[ x_new ] = [ cos(π/2) -sin(π/2) 0 ] [ 1 ] = [ 0 ]
[ y_new ] = [ sin(π/2) cos(π/2) 0 ] [ 0 ] = [ 1 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
The point (1, 0) is rotated to (0, 1), completing a 90° rotation.
4. Shearing
Shearing shifts one coordinate (x or y) based on the value of the other, effectively skewing
the shape. There are two types of shear: horizontal and vertical.
Horizontal Shearing Matrix:
[ x_new ] = [ 1 sh_x 0 ] [ x ]
[ y_new ] = [ 0 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Vertical Shearing Matrix:
[ x_new ] = [ 1 0 0 ] [ x ]
[ y_new ] = [ sh_y 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Example: Horizontally shearing a point (2, 3) by a factor of 1.5:
[ x_new ] = [ 1 1.5 0 ] [ 2 ] = [ 6 ]
[ y_new ] = [ 0 1 0 ] [ 3 ] = [ 3 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
The point (2, 3) is sheared to (6, 3), skewing it horizontally.
5. Reflection
Reflection flips a matrix over a given axis. Reflection can occur across the x-axis, y-axis, or
any line in the plane.
Reflection across the x-axis:
[ x_new ] = [ 1 0 0 ] [ x ]
[ y_new ] = [ 0 -1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Reflection across the y-axis:
[ x_new ] = [ -1 0 0 ] [ x ]
[ y_new ] = [ 0 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
Example: Reflecting a point (3, 4) across the x-axis:
[ x_new ] = [ 1 0 0 ] [ 3 ] = [ 3 ]
[ y_new ] = [ 0 -1 0 ] [ 4 ] = [ -4 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
The point (3, 4) is reflected to (3, -4) across the x-axis.