Tutorials on Advanced Math and Computer Science Concepts

Geometric Transformations

Geometric transformations are an example of a mapping used to manipulate vectors in space. They are typically used to do things like rotate, scale, and translate vectors across the space they occupy. Geometric transformations come up frequently in computer graphics, as well as physics and other branches of math.

We will first take a look at rotations to see how we can derive a function that rotates a vector by an angle $\theta$. To start, let's take a look at what a rotation does in $\mathbb{R}^2$ space.

In the x-direction, we can represent our rotated coordinate as: $\left[\begin{array}{cc} cos(\theta) \\ sin(\theta) \end{array}\right]$. Similarly, in the y-direction, we can represent our rotated coordinate as: $\left[\begin{array}{cc} -sin(\theta) \\ cos(\theta) \end{array}\right]$. If we combine the two components, we will get a matrix that will rotate any vector. This means that our rotation function can be written as:

$R_{\theta}(\vec{x}) = \left[\begin{array}{cc} cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta) \end{array}\right]\vec{x}$

Example: Rotate the vector $\left[\begin{array}{cc} 1 \\ 1 \end{array}\right]$ with $\theta = \frac{\pi}{4}$

To do this, we apply the same idea as our matrix mappings. We substitute theta into our rotation matrix, and multiply it by the vector we want to rotate. Doing so gives us the following:

$R_{\frac{\pi}{4}}(\left[\begin{array}{cc} 1 \\ 1 \end{array}\right]) = \left[\begin{array}{cc} cos(\frac{\pi}{4}} & - sin(\frac{\pi}{4}) \\ sin(\frac{\pi}{4}) & cos(\frac{\pi}{4}) \end{array}\right] \left[\begin{array}{cc} 1 \\ 1 \end{array}\right] = \left[\begin{array}{cc} cos(\frac{\pi}{4}) - sin(\frac{\pi}{4}) \\ sin(\frac{\pi}{4}) + cos(\frac{\pi}{4})\end{array}\right] $

We can further extend the idea of rotations into $\mathbb{R}^3$ space by slightly modifying the rotational matrix to account for the extra dimension. In $\mathbb{R}^3$, the rotational matrix is defined as follows:

$R_{\theta}(\vec{x}) = \left[\begin{array}{cc} cos(\theta) & -sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1 \end{array}\right]\vec{x}$

Our matrix is designed to rotate on the x and y coordinates, which is why the third column is set as the identity, $\left[\begin{array}{cc} 0 \\ 0 \\ 1 \end{array}\right]$. Aside from this, our matrix looks much the same as the $\mathbb{R}^2$ matrix.

Similar to rotation, we can also stretch, contract, and dilate vectors. A stretch will modify the first component, but leave the second component unchanged. To do this, we can use the following matrix: $\left[\begin{array}{cc} t & 0 \\ 0 & 1 \end{array}\right]$. If t < 1, we typically refer to this as a shrink, and if t > 1, we refer to this as a stretch.

Contractions and dilations are similar to stretches and shrinks, but they affect both components of the target vector. Due to this, the matrix ends up looking similar to the stretch, however both components are t. This gives us $\left[\begin{array}{cc} t & 0 \\ 0 & t \end{array}\right]$. If 0 < t < 1, the transformation is called a contraction. Otherwise, it is called a dilation.

A shear is a type of linear transformation that deforms a shape, in a similar way to translating a rectangle into a parallelogram. The matrix for this deformation looks like $\left[\begin{array}{cc} 1 & s \\ 0 & 1 \end{array}\right]$.

Finally, vectors can be reflected over the x and y axis using matrix transformations. If we are mirroring on the x axis, we use $\left[\begin{array}{cc} 1 & 0 \\ 0 & -1 \end{array}\right]$. If we are mirroring on the y axis, we use $\left[\begin{array}{cc} -1 & 0 \\ 0 & 1 \end{array}\right]$

In general, geometric translations are an important application of matrix mappings. If you continue in computer programming, you will often see these types of translations used for graphics, especially in game engines. Aside from programming, Physics often uses these types of translations for vectors that appear in problems.