|
In mathematics, in particular in linear algebra and geometry, a linear transformation can be represented by matrix multiplication. If A is a matrix and x a column vector,
- T(x) = Ax
is called multiplication by A.
The linear transformation T(x,y) = (x,y) would be represented by the identity matrix. T(x) = Ix = x, and would be known as the identity operator. It is useful, many times, to represent a transformation by using a matrix. It makes the calculations go quicker, and can make combining transformations much easier, such as for compositions of transformations.
Example: 2D graphics
In two dimensions, linear transformations can be represented using a 3×3 transformation matrix. Such transformations are useful, for example, in 2D computer graphics where translation corresponds to scrolling and scaling corresponds to zooming.
Translation
For translation (that is, moving all points a fixed amount horizontally and/or vertically), we have <math>x' = x + dx\,<math> and <math>y' = y + dy\,<math> for all points <math>(x,y)<math>. The corresponding transformation matrix calculation is:
- <math>
\begin{vmatrix} x' & y' & 1 \end{vmatrix} = \begin{vmatrix} x & y & 1 \end{vmatrix} \times \begin{vmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ dx & dy & 1 \end{vmatrix}
<math>
Scaling
For scaling (that is, enlarging or shrinking), we have <math>x' = x \cdot zx<math> and <math>y' = y \cdot zy<math>, and the matrix form is:
- <math>
\begin{vmatrix} x' & y' & 1 \end{vmatrix} = \begin{vmatrix} x & y & 1 \end{vmatrix} \times \begin{vmatrix} zx & 0 & 0 \\ 0 & zy & 0 \\ 0 & 0 & 1 \end{vmatrix}
<math>
Shearing
For shearing (for example, slanting a figure), we have <math>x' = x + sx \cdot y<math> and <math>y' = y + sy \cdot x<math>, and the matrix form is:
- <math>
\begin{vmatrix} x' & y' & 1 \end{vmatrix} = \begin{vmatrix} x & y & 1 \end{vmatrix} \times \begin{vmatrix} 1 && sy && 0 \\ sx && 1 && 0 \\ 0 && 0 && 1 \end{vmatrix}
<math>
Rotation
For rotation by an angle A counterclockwise about the origin, we have <math>x' = x \cos A - y \sin A\,<math> and <math>y' = x \sin A + y \cos A\,<math>, and the matrix form is:
- <math>
\begin{vmatrix} x' & y' & 1 \end{vmatrix} = \begin{vmatrix} x & y & 1 \end{vmatrix} \times \begin{vmatrix} \cos A & \sin A & 0 \\ -\sin A & \cos A & 0 \\ 0 & 0 & 1 \end{vmatrix}
<math>
Reflection
For reflection (that is, a mirror image) about one or both axes, simply use a scale factor of -1 for zx and/or zy (see Scaling above).
Composite transformations
It is important to note that transformation matricies can be combined using ordinary matrix multiplication. For example, if we want to both translate and scale all points, we could apply the two appropriate matrices from above to each point; but a better way would be to multiply the two matrices to get a new, combined transformation matrix and then apply that single new matrix to each point.
Multiplying transformation matrices results in a composition of the transformations. In general, matrix multiplication is not commutative, so the order of multiplication is important. Transforming with the product matrix A × B is equivalent to transforming with B first and then A.
An important special-case composite transformation represents translation by <math>(dx,dy)<math> followed by scaling by <math>(zx,zy)<math>. The matrix for this is simply:
- <math>
\begin{vmatrix} zx & 0 & 0 \\ 0 & zy & 0 \\ dx & dy & 1 \end{vmatrix}
<math>
Calculating coordinates
Once a transformation matrix (call it T) has been calculated, <math>(x',y')<math> for each point <math>(x,y)<math> can be calculated using the rules for matrix multiplication. Note that all transformation matricies considered here have the third column equal to <math> \begin{vmatrix} 0 \\ 0 \\ 1 \end{vmatrix} <math>.
- <math>x' = x \cdot T_{11} + y \cdot T_{21} + T_{31}<math>
- <math>y' = x \cdot T_{12} + y \cdot T_{22} + T_{32}<math>
Reverse transformations
It is possible to perform a reverse transformation by calculating the inverse of the matrix. This would be useful, for example, in 2D computer graphics to interpret a mouse-down event. To calculate the inverse U of T in the 2D case:
- Calculate the determinant <math>d = T_{22} \cdot T_{11} - T_{21} \cdot T_{12}<math>
- <math> U_{11} = T_{22} / d \,<math>
- <math> U_{12} = - T_{12} / d \,<math>
- <math> U_{13} = 0 \,<math>
- <math> U_{21} = - T_{21} / d \,<math>
- <math> U_{22} = T_{11} / d \,<math>
- <math> U_{23} = 0 \,<math>
- <math> U_{31} = ( T_{32} \cdot T_{21} - T_{31} \cdot T_{22} ) / d \,<math>
- <math> U_{32} = ( - T_{32} \cdot T_{11} + T_{31} \cdot T_{12} ) / d \,<math>
- <math> U_{33} = 1 \,<math>
One can then calculate
- <math>
\begin{vmatrix} x && y && 1 \end{vmatrix} = \begin{vmatrix} x' && y' && 1 \end{vmatrix} \times U
\,<math>
using formulae analogous to the above (see Calculating coordinates).
Generalization
Generalization of these methods to three dimensions (using a 4×4 matrix) and higher is possible.
|