Link to this document's Jupyter Notebook

In order to successfully complete this assignment you need to participate both individually and in groups during class. If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class. If you are attending asynchronously, turn in your assignment using D2L no later than 11:59pm on the day of class. See links at the end of this document for access to the class timeline for your section.


In-Class Assignment: Transformations

Image from: https://people.gnome.org/~mathieu/libart/libart-affine-transformation-matrices.html

Agenda for today's class (80 minutes)

</p>

  1. (20 minutes) Review of Pre-Class Assignment
  2. (20 minutes) Homework 1 Review
  3. (20 minutes) Affine Transforms
  4. (20 minutes) Fractals

1. Review of Pre-Class Assignment


2. Homework 1 Review


3. Affine Transforms

In this section, we are going to explore different types of transformation matrices. The following code is designed to demonstrate the properties of some different transformation matrices.

DO THIS: Review the following code.

Example Scaling Matrix

Example Translation Matrix

Example Reflection Matrix

Example Rotation Matrix

Example Shear Matrix

Combine Transforms

We have five transforms $R$, $S$, $T$, $Re$, and $SH$

DO THIS: Construct a ($3 \times 3$) transformation Matrix (called $M$) which combines these five transforms into a single matrix. You can choose different orders for these five matrix, then compare your result with other students.

Questions: Did you can get the same result with others? You can compare the matrix $M$ to see the difference. If not, can you explain why it happens?

Put your answer here

Interactive Example

The following command can also be used but it may be slow on some peoples computers.

DO THIS: Using the above interactive enviornment to see if you can figure out the transformation matrix to make the following image:

Questions: What where the input values?

Put your answer here:

r =

scale =

dx =

dy =

shx =

shy =


3. Fractals

In this section we are going to explore using transformations to generate fractals. Consider the following set of linear equations. Each one takes a 2D point as input, applies a $2 \times 2$ transform, and then also translates by a $2 \times 1$ translation matrix

$$ T_1:\left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] = \left[ \begin{matrix} 0.86 & 0.03 \\ -0.03 & 0.86 \end{matrix} \right] \left[ \begin{matrix} x_0 \\ y_0 \end{matrix} \right] + \left[\begin{matrix} 0\\ 1.5 \end{matrix} \right] : probability = 0.83 $$

$$ T_2: \left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] = \left[ \begin{matrix} 0.2 & -0.25 \\ 0.21 & 0.23 \end{matrix} \right] \left[ \begin{matrix} x_0 \\ y_0 \end{matrix} \right] + \left[\begin{matrix} 0\\ 1.5 \end{matrix} \right] : probability = 0.08 $$

$$ T_3 : \left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] = \left[ \begin{matrix} 0.15 & 0.27 \\ 0.25 & 0.26 \end{matrix} \right] \left[ \begin{matrix} x_0 \\ y_0 \end{matrix} \right] + \left[\begin{matrix} 0\\ 0.45 \end{matrix} \right] : probability = 0.08 $$

$$ T_4: \left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] = \left[ \begin{matrix} 0 & 0 \\ 0 & 0.17 \end{matrix} \right] \left[ \begin{matrix} x_0 \\ y_0 \end{matrix} \right] + \left[\begin{matrix} 0\\ 0 \end{matrix} \right] : probability = 0.01 $$

We want to write a program that use the above transformations to "randomly" generate an image. We start with a point at the origin (0,0) and then randomly pick one of the above transformation based on their probability, update the point position and then randomly pick another point. Each matrix adds a bit of rotation and translation with $T_4$ as a kind of restart.

To try to make our program a little easier, lets rewrite the above equations to make a system of "equivelent" equations of the form $Ax=b$ with only one matrix. We do this by adding an additional variable variable $z=1$. For example, verify that the following equation is the same as equation for $T1$ above:

$$ T_1: \left[ \begin{matrix} x_1 \\ y_1 \end{matrix} \right] = \left[ \begin{matrix} 0.86 & 0.03 & 0 \\ -0.03 & 0.86 & 1.5 \end{matrix} \right] \left[ \begin{matrix} x_0 \\ y_0 \\ 1 \end{matrix} \right] $$

Please NOTE that we do not change the value for $z$, and it is always be $1$.

DO THIS: Verify the $Ax=b$ format will generate the same answer as the $T1$ equation above.

The following is some pseudocode that we will be using to generate the Fractals:

  1. Let $x = 0$, $y = 0$, $z=1$
  2. Use a random generator to select one of the affine transformations $T_i$ according to the given probabilities.
  3. Let $(x',y') = T_i(x,y,z)$.
  4. Plot $(x', y')$
  5. Let $(x,y) = (x',y')$
  6. Repeat Steps 2, 3, 4, and 5 one thousand times.

The following python code implements the above pseudocode with only the $T1$ matrix:

DO THIS: Modify the above code to add in the $T2$, $T3$ and $T4$ transforms.

QUESTION: Describe in words for the actions performed by $T_1$, $T_2$, $T_3$, and $T_4$.

$T_1$: Put your answer here

$T_2$: Put your answer here

$T_3$: Put your answer here

$T_4$: Put your answer here

DO THIS: Using the same ideas to design and build your own fractal. You are welcome to get inspiration from the internet. Make sure you document where your inspiration comes from. Try to build something fun, unique and different. Show what you come up with with your instructors.


Congratulations, we're done!

If you attend class in-person then have one of the instructors check your notebook and sign you out before leaving class. If you are attending asynchronously, turn in your assignment using D2L.

Course Resources:

Written by Dr. Dirk Colbry, Michigan State University Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.