Affine transformations are a class of mathematical operations that encompass rotation, scaling, translation, shearing, and several similar transformations that are regularly used for various applications in mathematics and computer graphics. To start, we will draw a distinct (yet thin) line between affine and linear transformations before discussing the augmented matrix formalism typically used in practice.
Let us start with a provided point,
Here,
Here,
Description | Transform |
---|---|
Scaling along |
|
Scaling along |
|
Shearing along |
|
Shearing along |
|
Translation along |
|
Translation along |
For all of these visualizations, we show a set of 4 points that are assigned to the vertices of a square.
Initially,
The hope is that these visualizations show that each element within
I will be honest, when I initially learned how to perform rotation with a linear transformation, I did not really understand how it worked. For this reason, I think it is important to delve a bit deeper into this topic, hopefully providing an intuitive explanation for those who are new (and potentially those who already use the rotation matrix regularly, but do not fully understand it).
If someone were to take the set of dials shown above and mix them to create a rotational effect, they might start by shearing in one direction along
Here, we see that (at least for angles less than
Well, the answer is not particularly surprising.
If we want to rotate our points, we probably are already imagining this rotation along a circle with some angle
In this case, the amount we want to shear should start at 0 when
This seems right, but it is worth dwelling on this a bit more.
If the scale factor is 0 at
This means that even though the scaling components are 0, the shear components are
$$ \begin{align} \begin{bmatrix} 1 & 0 \ 0 & 1 \ \end{bmatrix} \begin{bmatrix} 1 \ 2 \ \end{bmatrix} &= \begin{bmatrix} 1 \ 2 \ \end{bmatrix},\
\begin{bmatrix} 0 & -1 \ 1 & 0 \ \end{bmatrix} \begin{bmatrix} 1 \ 2 \ \end{bmatrix} &= \begin{bmatrix} -2 \ 1 \ \end{bmatrix}.
\end{align} $$
Here, we see that when multiplying by the identity matrix, the vector remains the same, but when multiplying by the second matrix, the x and y components flip. Essentially, all of the vector magnitude moved into the "shear" component, while none of it remains in the "scale" component.
My point is that even though it is useful to think of two of our dials as scale factors along
Before continuing to show what the
Description | Transform |
---|---|
Just sines | |
Just cosines |
Here, we see two completely different behaviors:
- In the sine-only case, we see that as
$$\theta$$ wraps around from$$0 \rightarrow 2\pi$$ , the square seems to grow and rotate like expected, but at$$\pi/2$$ , it somewhat abruptly decides to move in the other direction. - In cosine-only case, we see the square flip around entirely at
$$\pi/2$$ .
Before watching the next video, it is important to think for a little bit about how these two different interactions will work together in practice. When you are ready, go ahead and click the play button:
At least for me, it took some thinking to figure out why the two animations above create rotation when put together.
When thinking about it, it makes sense that at
Overall, the rotation matrix is a fun and interesting application to linear transformations that really helped me understand how the entire class of operations can be used to create more complicated movements.
At this stage, we have discussed what affine transforms are from a functional perspective; however, (as always) there is a lot more to discuss. This particular chapter is meant to provide an intuitive feel for the transformations for those who might need to use them for whatever application they need, so I am hesitant to dive too deeply into more rigorous definitions; however, it is important to talk about certain properties of affine transforms that make them suitable for a wide variety of applications. Namely, affine transformations preserve the following:
- collinearity between points. This means that any points that are on the same line before an affine transform must be on that same line after the transformation. The line can still change in slope or position.
- parallelism between lines. Any lines parallel before the transform must also be parallel after.
-
ratios of the lengths of parallel line segments. This means if you have two different line segments, one of which is parameterized by
$$p_1$$ and$$p_2$$ , while the other is parameterized by$$p_3$$ and$$p_4$$ , then$$\frac{\vec{p_1 p_2}}{\vec{p_3 p_4}}$$ must be the same before and after transformation. - convexity of any transformed shape. If a shape does not have any concave component (a point that points in towards its center), then it cannot have a concave component after the transformation.
- barycenters of the collection of points. The barycenter is the collective center of mass of the system, like the balancing point for a plate. Essentially, there is an equal amount of "stuff" on either side of the barycenter. This location must remain at the same location relative to each point after transformation.
Again, there is a lot more we could talk about, but I feel we will leave more rigorous discussions for later if we need them for subsequent algorithms. Instead, I believe it is useful to move on to a relatively common implementation of affine transformations: the augmented matrix formalism.
As stated before, affine transformations are basically a mix of a transformation matrix and translation.
For two-dimensional input vectors, the augmented matrix formalism combines both of these into a large
To be honest, the answer feels like a bit of a hack: we simply append a 1 to the end of the input, output, and translation vectors, such that:
\left[\begin{array}{@{}ccc|c@{}} & \mathbf{A} & & \ell \ 0 & \cdots & 0 & 1 \ \end{array}\right] \begin{bmatrix} \mathbf{v}_0 \ 1 \end{bmatrix} $$
So, using
we would perform the following computation:
\left[\begin{array}{@{}cc|c@{}} 0 & -1 & 0 \ 1 & 0 & 0 \ 0 & 0 & 1 \ \end{array}\right] \begin{bmatrix} 1 \ 2 \ 1 \end{bmatrix} $$
Doing this, we find that
Appending the 1 to the end of the two-dimensional vectors essentially turn them into three-dimensional vectors, with the
Description | Transform |
---|---|
Scaling along |
|
Scaling along |
|
Shearing along |
|
Shearing along |
|
Translation along |
|
Translation along |
The shear and scaling operations seem about the same as before; however, the translation operations are now clearly a shear along the entire cube!
The only reason this acts as translation for two dimensions is because we only care about the slice through the cube at
Now, the reason I always feel this implementation is a bit hacky is because there is a little magic that everyone keeps quiet about: the last row in the matrix.
With all of the operations shown above, it was simply set to
What would happen if we actually moved those dials and modified the bottom row? Well...
Description | Transform |
---|---|
Shearing along |
|
Shearing along |
|
Scaling along |
In this case, the first two components are shearing along
Finally, let us go back to the rotation example:
Here, we see that we can embed just about any affine transformation into three dimensional space and still see the same results as in the two dimensional case.
I think that is a nice note to end on: affine transformations are linear transformations in an
Here is a video describing affine transformations:
The code examples are licensed under the MIT license (found in LICENSE.md).
The text of this chapter was written by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A11 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A22 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A12 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A21 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A13 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A23 square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "Semi Rotate" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "Sines" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "Cosines" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "Rotate Square" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A11 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A22 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A12 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A21 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A13 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A23 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A31 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A32 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "A33 cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
- The video "Rotation cube" was created by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.