SUNY Geneseo Department of Mathematics

Lab 4—Matrices

Math 230 01
Fall 2015
Prof. Doug Baldwin

Complete by Monday, October 19
Grade by Thursday, October 22

Purpose

This lesson develops your ability to use matrices and matrix operations in Matlab. It also reinforces your ability to program with functions.

Background

We discussed (or will discuss) matrices and matrix operations in class between October 9 and October 16. Our textbook covers this material in chapter 9.

This exercise asks you to use matrices to apply certain geometric transformations to plotted images. The key idea behind doing this is that if (x,y) is a point, then many geometric transformations can be generated by multiplying the column vector

        x
        y
	

by an appropriate matrix. We will look at examples in class. You can also get some insight into how these transformations work by applying them by hand to simple points.

For example, you can move the point to new coordinates (ax,by) by multiplying it by the matrix

	    a    0
	    0    b
	

If you multiply every point in some figure centered on (or otherwise referenced to) the origin by such a matrix, the effect is to make it a times bigger in the x dimension and b times bigger in the y dimension. For this reason, this transformation is called dilation or scaling.

You can also rotate a point counterclockwise around the origin through angle Θ by multiplying it by the matrix

	    cosΘ    -sinΘ
	    sinΘ     cosΘ
	

Use a negative Θ to rotate clockwise. Once again, multiplying all points in a figure centered at the origin by such a matrix rotates the entire figure; if the figure isn’t centered at the origin the effect is as if the object was orbitting the origin.

Finally, you can do what is called shearing, which amounts to moving a point a distance in the x direction by an amount proportional to its y coordinate by multiplying by the matrix

	    1    k
	    0    1
	

where k determines how pronounced the shear is: a point will move k units in the x direction for every 1 unit in its y coordinate; k is typically less than 1.

Visually, shearing every point in an object makes it lean.

Activity

I have shared a “.m” file named “stickPerson.m” with you on Google Drive or via download from the web. (If you can’t find it one of these ways, let me know and I will get it to you in some other way.) This file defines a function named stickPerson that draws a stick figure person (who is named Stick Person in the following discussion) when called, like so:

Stick figure standing person

Your job is to do several things with this function, as follows:

Step 1

Modify the stickPerson function so that it takes one argument, namely a matrix that describes a transformation of Stick Person. The modified function should apply this transformation to every point in Stick Person before drawing the person, so that what it actually draws is a transformed person. The pictures below give some examples of transformed Stick Persons.

Test your modified function by calling it with a transformation that does nothing (i.e., an identity matrix) and verifying that it draws the figure shown above.

Step 2

Write a script (or a section in a larger script) that calls your modified stickPerson function with a transformation that makes it draw a tall skinny Stick Person (this example is 1.5 times taller than normal and 0.75 times as thick):

Narrow stick figure person

Step 3

Write a script (or a section) that calls your stickPerson function with a transformation that makes it draw Stick Person leaning into the wind (or maybe beckoning a Stick Person horde to follow somewhere):

Stick figure person leaning right

Once you have a matrix that makes Stick Person lean a certain amount, see if you can figure out how to compute from it other matrices that make Stick Person lean twice as much, three times as much, or in general any positive integer amount as much. Try your ideas by adding suitable code to your script.

Step 4

Finally, write a script (or a section) that uses your stickPerson function to draw Stick Person doing a one-arm push-up:

Stick figure leaning on its hand

In writing this code, see if you can use Matlab to calculate how far you need to rotate Stick Person in order to get the push-up effect. In doing this, it will help to know that the untransformed Stick Person’s right foot is on the origin, and that its right hand is at (0.5, 3).

Extras

If you have time after doing the above, there are lots of extra things you can do with this lab. For example, see if you can invent other interesting transformations of Stick Person. Try figuring out how you would apply several transformations at once, for example to draw the tall skinny Stick Person doing a push-up. Or just try making the basic Stick Person drawing look more sophisticated. Or use your imagination to invent other extensions…. Have fun!

Follow-Up

I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring a written solution to the exercise to your meeting, as that will speed the process along.

Sign up for a meeting via Google calendar. If you worked in a group on this exercise, the whole group should schedule a single meeting with me. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.