Content
- What is a transformation?
- Types of transformations
- Translation
- Rotation
Graphics 1 CMP-5010B
Dr. David Greenwood
February, 2022
…in computer graphics?
…in 2D Computer Graphics
Geometric transformations will map points in one space to points in another space:
\[(x',y') = f(x,y)\]
The mapping function uses elementary operations, which include:
Types of transformation preserve geometric properties of the object.
In graphics, we represent objects using points or vertices, which are connected to form polygons or faces.
Only the vertices are subjected to the transformations.
Question: How do we represent a vertex mathematically?
Transformations of an object are applied to each individual vertex of that object.
The mathematical entity used to perform a transformation to the vector of n vertex coordinates is:
A square matrix of size \(n\) x \(n\), where \(n\) is the dimension of the vertex vector.
Formally, we will represent vertex coordinates as a column vector:
\[\begin{bmatrix} x \\ y \end{bmatrix}\]
Translation is performed by adding a translation vector.
\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} t_x \\ t_y \end{bmatrix} \]
Example: Consider the vertex with coordinates \(~(-5, -2)\), that we wish to translate in the \(~x~\) direction 9 units, and in the \(~y~\) direction 5 units.
\[ \begin{bmatrix} 4 \\ 3 \end{bmatrix} = \begin{bmatrix} -5 \\ -2 \end{bmatrix} + \begin{bmatrix} 9 \\ 5 \end{bmatrix} \]
\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} t_x \\ t_y \end{bmatrix} \]
We stated earlier, that the mathematical entity used to perform a transformations to the vector coordinates is a matrix.
How do we use a matrix to perform a transformation?
A mnemonic for trigonometry is SOH, CAH, TOA.
\[ sin(\theta) = \frac{O}{H},~ cos(\theta) = \frac{A}{H},~ tan(\theta) = \frac{O}{A} \]
We can fit this mnemonic to our 2D plane:
\[ sin(\theta) = \frac{O}{H} = \frac{y}{r},~ cos(\theta) = \frac{A}{H} = \frac{x}{r},~ tan(\theta) = \frac{O}{A} = \frac{y}{x} \]
where \(r\) is the radius of a circle.
Matrix multiplication is performed row by column:
\[ \begin{bmatrix} ax + by \\ cx + dy \end{bmatrix} = \begin{bmatrix} a~ ~b \\ c~ ~d \end{bmatrix} \times \begin{bmatrix} x \\ y \end{bmatrix} \]
Deriving the rotation matrix using trigonometric identities.
\[ r = \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} \cos \beta \\ \sin \beta \end{bmatrix} \]
\[ r' = \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos (\alpha + \beta) \\ \sin (\alpha + \beta) \end{bmatrix} \]
The sum of two angles:
\[\cos (\alpha + \beta) = \cos \alpha ~ \cos \beta - \sin \alpha ~ \sin \beta\] \[\sin (\alpha + \beta) = \sin \alpha ~ \cos \beta + \cos \alpha ~ \sin \beta\]
using the identities:
\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \alpha ~ \cos \beta - \sin \alpha ~ \sin \beta \\ \sin \alpha ~ \cos \beta + \cos \alpha ~ \sin \beta \end{bmatrix} \]
recall:
\[ \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} \cos \beta \\ \sin \beta \end{bmatrix} \]
substitute \(x\) and \(y\):
\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} x \cos \alpha - y \sin \alpha \\ x \sin \alpha + y \cos \alpha \end{bmatrix} \]
as a matrix multiplication:
\[ \begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} \cos \alpha &-\sin \alpha \\ \sin \alpha &~\cos \alpha \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} \]
\[ R = \begin{bmatrix} \cos \alpha &-\sin \alpha \\ \sin \alpha &~\cos \alpha \end{bmatrix} \]
Reading: