Transformation Matrix

From Math Images

(Difference between revisions)
Jump to: navigation, search
(Rotation)
Current revision (14:15, 19 July 2011) (edit) (undo)
(2D Affine Transformations)
 
(9 intermediate revisions not shown.)
Line 1: Line 1:
A '''transformation matrix''' is a special matrix that can describe 2d and 3d transformations. Transformations are frequently used in linear algebra and computer graphics, since transformations can be easily represented, combined and computed.
A '''transformation matrix''' is a special matrix that can describe 2d and 3d transformations. Transformations are frequently used in linear algebra and computer graphics, since transformations can be easily represented, combined and computed.
===Computing Transformations===
===Computing Transformations===
-
If you have a transformation matrix you can evaluate the transformation that would be performed by multiplying the transformation matrix by the original array of points. For example in 2d suppose you had a trandformation matrix of <math>\begin{bmatrix} a & b \\ c & d \end{bmatrix}</math> then the transfomations of the points <math>\begin{bmatrix} x \\ y \end{bmatrix}</math> would be <math>\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}</math>. Similarly, to perform 3d transformation <math>\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}</math> on the points <math>\begin{bmatrix} x \\ y \\ z \end{bmatrix}</math> you would use <math>\begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix}</math>
+
If you have a transformation matrix you can evaluate the transformation that would be performed by multiplying the transformation matrix by the original array of points. For example in 2d suppose you had a transformation matrix of <math>\begin{bmatrix} a & b \\ c & d \end{bmatrix}</math> then the transfomations of the points <math>\begin{bmatrix} x \\ y \end{bmatrix}</math> would be <math>\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}</math>. Similarly, to perform 3d transformation <math>\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}</math> on the points <math>\begin{bmatrix} x \\ y \\ z \end{bmatrix}</math> you would use <math>\begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix}</math>
 +
 
===Examples in 2D Graphics===
===Examples in 2D Graphics===
In 2D graphics Linear transformations can be represented by 2x2 matrices. Most common transformations such as rotation, scaling, shearing, and reflection are linear transformations and can be represented in the 2x2 matrix. Other affine transformations can be represented in a 3x3 matrix.
In 2D graphics Linear transformations can be represented by 2x2 matrices. Most common transformations such as rotation, scaling, shearing, and reflection are linear transformations and can be represented in the 2x2 matrix. Other affine transformations can be represented in a 3x3 matrix.
Line 35: Line 36:
</math>
</math>
===2D Affine Transformations===
===2D Affine Transformations===
-
Affine transformations are represented by transformation matrices that are one higher dimension then the regular transformations. For example a 2d shear transformation <math>\begin{bmatrix} 1 & k \\ 0 & 1 \end{bmatrix}</math> could be represented by the affine transformation matrix <math>\begin{bmatrix} 1 & k & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}</math>. The transformation performed by the affine transformation matrix can be found in the same manner as a regular transformation matrix with 1 extra dimension added on the matrix and vector or orignal points. Instead of performing the transformation on the points <math>\begin{bmatrix} x \\ y \end{bmatrix}</math> you would perform the transformation on the points <math>\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}</math>. If you calculate the transformation you end up with <math>\begin{bmatrix} x \\ y \\ w \end{bmatrix}</math> where w is a value that you can discard if you are only interested in the (x,y) transfomration.
+
Affine transformations are represented by transformation matrices that are one higher dimension than the regular transformations. For example a 2d shear transformation <math>\begin{bmatrix} 1 & k \\ 0 & 1 \end{bmatrix}</math> could be represented by the affine transformation matrix <math>\begin{bmatrix} 1 & k & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}</math>. The transformation performed by the affine transformation matrix can be found in the same manner as a regular transformation matrix with 1 extra dimension added on the matrix and vector or orignal points. Instead of performing the transformation on the points <math>\begin{bmatrix} x \\ y \end{bmatrix}</math> you would perform the transformation on the points <math>\begin{bmatrix} x \\ y \\ 1 \end{bmatrix}</math>. If you calculate the transformation you end up with <math>\begin{bmatrix} x \\ y \\ w \end{bmatrix}</math> where w is a value that you can discard if you are only interested in the (x,y) transformation.
====Translation====
====Translation====
Affine transformations are typically used instead because only affine transformations allow translations. The matrix form of x and y translation is:
Affine transformations are typically used instead because only affine transformations allow translations. The matrix form of x and y translation is:
<math>\begin{bmatrix} 1 & 0 & T_x \\ 0 & 1 & T_y \\ 0 & 0 & 1 \end{bmatrix}</math>
<math>\begin{bmatrix} 1 & 0 & T_x \\ 0 & 1 & T_y \\ 0 & 0 & 1 \end{bmatrix}</math>
 +
===2D Transformation applet===
===2D Transformation applet===
<java_applet code="Transform2.class" width="600" height="450" archive="Jama-1.0.2.jar" />
<java_applet code="Transform2.class" width="600" height="450" archive="Jama-1.0.2.jar" />
Line 49: Line 51:
====Rotation====
====Rotation====
There are three different sets of rotation in the three dimenstional transformation matrix, one for each axis that can be rotated around.
There are three different sets of rotation in the three dimenstional transformation matrix, one for each axis that can be rotated around.
-
X axis rotation: :<math>\begin{bmatrix}1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{bmatrix}</math>
+
 
-
Y axis rotation: :<math>\begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix}</math>
+
X axis rotation: <math>\begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{bmatrix}</math>
-
Z axis rotation: :<math>\begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix}</math>
+
 
 +
Y axis rotation: <math>\begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix}</math>
 +
 
 +
Z axis rotation: <math>\begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix}</math>
 +
 
 +
===3d Transformation Applet===
 +
<htmlet>XformApp</htmlet>
===Composing transformations===
===Composing transformations===
The ability to compose multiple transformation matrix into one matrix is very convenient when you are to calculate many transformations. You can take any number of individual transformations and combine them into a single transformation matrix by multiplying the matrices together. It is important to remember that the order in which you multiply the matrices together is significant.
The ability to compose multiple transformation matrix into one matrix is very convenient when you are to calculate many transformations. You can take any number of individual transformations and combine them into a single transformation matrix by multiplying the matrices together. It is important to remember that the order in which you multiply the matrices together is significant.

Current revision

A transformation matrix is a special matrix that can describe 2d and 3d transformations. Transformations are frequently used in linear algebra and computer graphics, since transformations can be easily represented, combined and computed.

Contents

Computing Transformations

If you have a transformation matrix you can evaluate the transformation that would be performed by multiplying the transformation matrix by the original array of points. For example in 2d suppose you had a transformation matrix of \begin{bmatrix} a & b \\ c & d \end{bmatrix} then the transfomations of the points \begin{bmatrix} x \\ y \end{bmatrix} would be \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} a & b \\ c & d \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}. Similarly, to perform 3d transformation \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix} on the points \begin{bmatrix} x \\ y \\ z \end{bmatrix} you would use \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix} = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \end{bmatrix}\begin{bmatrix} x \\ y \\ z \end{bmatrix}

Examples in 2D Graphics

In 2D graphics Linear transformations can be represented by 2x2 matrices. Most common transformations such as rotation, scaling, shearing, and reflection are linear transformations and can be represented in the 2x2 matrix. Other affine transformations can be represented in a 3x3 matrix.

Rotation

For rotation by an angle θ clockwise about the origin, the functional form is x' = xcosθ + ysinθ and y' = − xsinθ + ycosθ. Written in matrix form, this becomes:


\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \theta &  \sin\theta \\ -\sin \theta & \cos \theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

Similarly, for a rotation counterclockwise about the origin, the functional form is x' = x \cos \theta - y \sin \theta and y' =  x \sin \theta + y \cos \theta and the matrix form is:


\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \theta &  -\sin\theta \\ \sin \theta & \cos \theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

Scaling

For scaling we have x' = s_x \cdot x and y' = s_y \cdot y. The matrix form is:


\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} s_x & 0 \\ 0 & s_y \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

Shearing

For shear mapping (visually similar to slanting), there are two possibilities. For a shear parallel to the x axis has x' = x + ky and y' = y; the shear matrix, applied to column vectors, is:


\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1 & k \\ 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

A shear parallel to the y axis has x' = x and y' = y + kx, which has matrix form:


\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} 1 & 0 \\ k & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix}

2D Affine Transformations

Affine transformations are represented by transformation matrices that are one higher dimension than the regular transformations. For example a 2d shear transformation \begin{bmatrix} 1 & k \\ 0 & 1 \end{bmatrix} could be represented by the affine transformation matrix \begin{bmatrix} 1 & k & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}. The transformation performed by the affine transformation matrix can be found in the same manner as a regular transformation matrix with 1 extra dimension added on the matrix and vector or orignal points. Instead of performing the transformation on the points \begin{bmatrix} x \\ y \end{bmatrix} you would perform the transformation on the points \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}. If you calculate the transformation you end up with \begin{bmatrix} x \\ y \\ w \end{bmatrix} where w is a value that you can discard if you are only interested in the (x,y) transformation.

Translation

Affine transformations are typically used instead because only affine transformations allow translations. The matrix form of x and y translation is: \begin{bmatrix} 1 & 0 & T_x \\ 0 & 1 & T_y \\ 0 & 0 & 1 \end{bmatrix}

2D Transformation applet

If you can see this message, you do not have the Java software required to view the applet.

Examples in 3D Graphics

Objects in three dimensions can be transformed using transformation matrices in the same way as two dimensional objects. Three dimensional transformation matrices are 3x3 matrices. Three dimensional affine transformation matrices are 4x4 matrices.

Scale

For scaling we have x' = s_x \cdot x, y' = s_y \cdot y and z' = s_z \cdot z. The matrix form is: \begin{bmatrix} s_x & 0 & 0  \\ 0 & s_y & 0 \\ 0 & 0 & s_z \end{bmatrix}

Rotation

There are three different sets of rotation in the three dimenstional transformation matrix, one for each axis that can be rotated around.

X axis rotation: \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{bmatrix}

Y axis rotation: \begin{bmatrix} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{bmatrix}

Z axis rotation: \begin{bmatrix} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{bmatrix}

3d Transformation Applet

Matrix Transformation Applet

Composing transformations

The ability to compose multiple transformation matrix into one matrix is very convenient when you are to calculate many transformations. You can take any number of individual transformations and combine them into a single transformation matrix by multiplying the matrices together. It is important to remember that the order in which you multiply the matrices together is significant.

Personal tools