|
|
|
|
|
Transformation MatrixIn 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 very often useful to represent a transformation by a matrix, this reduces the calculation time and enables the combining 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 and for all points . The corresponding transformation matrix calculation is: -
\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} Scaling For scaling (that is, enlarging or shrinking), we have and , and the matrix form is: -
\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} Shearing For shearing (for example, slanting a figure), we have and , and the matrix form is: -
\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} Rotation For rotation by an angle A counterclockwise about the origin, we have and , and the matrix form is: -
\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} 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 followed by scaling by . The matrix for this is simply: -
\begin{vmatrix} zx & 0 & 0 \\ 0 & zy & 0 \\ dx & dy & 1 \end{vmatrix} Calculating coordinates Once a transformation matrix (call it T) has been calculated, for each point can be calculated using the rules for matrix multiplication. Note that all transformation matricies considered here have the third column equal to . 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
-
-
-
-
-
-
-
-
-
One can then calculate -
\begin{vmatrix} x && y && 1 \end{vmatrix} = \begin{vmatrix} x' && y' && 1 \end{vmatrix} \times U \, 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.
|
 |
|
| Copyright 2005-2009 OnPedia.com. All Rights Reserved |
|
|