2D Matrix Transformations G
2D Matrix Transformations G
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 ]
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:
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.
[ x_new ] = [ 1 sh_x 0 ] [ x ]
[ y_new ] = [ 0 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
[ x_new ] = [ 1 0 0 ] [ x ]
[ y_new ] = [ sh_y 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
[ x_new ] = [ 1 1.5 0 ] [ 2 ] = [ 6 ]
[ y_new ] = [ 0 1 0 ] [ 3 ] = [ 3 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]
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.
[ x_new ] = [ 1 0 0 ] [ x ]
[ y_new ] = [ 0 -1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
[ x_new ] = [ -1 0 0 ] [ x ]
[ y_new ] = [ 0 1 0 ] [ y ]
[ 1 ] = [ 0 0 1 ] [ 1 ]
[ x_new ] = [ 1 0 0 ] [ 3 ] = [ 3 ]
[ y_new ] = [ 0 -1 0 ] [ 4 ] = [ -4 ]
[ 1 ] = [ 0 0 1 ] [ 1 ] = [ 1 ]