Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Engr 3: Intro to Programming

Summer 2021

Homework 5


Please remember to include comments in your programs.


1. Give us a hand. (5 points) In this problem you will produce a plot of your own left hand. Download the files capture_hand.m and dot_to_dot.m into your working directory. Run capture_hand.m. Then place your left hand on the computer screen. Use the mouse to select a few dozen points outlining your hand. Press ’enter’ when you are done choosing points. To make sure that it worked, type the following in the Command Window:

which should show the outline of your hand. Save your data in the file myhand.mat with the command

Please submit the file myhand.mat


2. Give us more hands. (10 points) In this problem you will perform transformations on the data points in myhand.mat to make versions of the requested plots for your hand. In particular, you will need to fill in the appropriate matrices A, B, and products of A’s and B’s in the code given below. Save the completed file as transform_hands.m

Please see the figure which shows what your output should look like.

● Your figure(1) should be a plot of your left hand.

● Your figure(2) should be generated by taking the data for your left hand, and transforming it using a matrix A so that it has been flipped over the x-axis.

● Your figure(3) should be generated by taking the data for your left hand, and transforming it using a matrix B to give a left hand which is half the size of the hand shown in figure(1) and is rotated as shown.

● Your figure(4) should be generated by taking the data for your left hand, and transforming it using some product of the matrices A and B to give a right hand which is half-size and rotated as shown.

● Your figure(5) should be generated by taking the data for your left hand, and transforming it using some product of the matrices A and B to give a left hand which is half-size and rotated as shown.

Please submit the file transform_hands.m


3. Synchronized Translations (30 points) In this problem, we will write a function called shift.m which allows us to translate a three-dimensional object along the x, y, or z axis by some specified amount. We will use this function to create a cool movie showing moving objects.

        On GauchoSpace, there are files called setup.m and show2.m. These generate and plot an object that we’ll translate in various ways, using show2.m to visualize the results. It isn’t important to understand the details of the commands in these files, just how to use them. For example, if you download these files then type

you’ll see the object. Note that we will always call show2.m with the same variable T as the first argument. The second argument will be a translation of S obtained through a call to the function that you’ll write.

a) (10 pts) Write a function shift.m which takes as input a 3 × n matrix S (for example, as obtained from running setup.m), a scalar dist which gives the distance that the object should translate, and a string ’x’, ’y’, or ’z’ which tells which axis you want to translate along.

        This function should return a matrix of the same size as S, but with all elements in the first row equal to their original values plus dist if the input string is ’x’, all elements in the second row equal to their original values plus dist if the input string is ’y’, and all elements in the third row equal to their original values plus dist if the input string is ’z’.

        These actions correspond to translations of the object along the specified axis. For example, the commands 

should show the object translated by a distance of 80 along the x-axis.

b) (20 pts) Here you will write Matlab script called shift_movie.m which shows a movie with three objects moving in the following ways. Except for the first one, each of these steps should show multiple frames, which when shown in succession give a movie.

● The three objects start on top of each other at their default position.

● One object translates by increasing amounts in the +x direction, and one translates by the same magnitudes in the −x direction, until they are a distance of 80 away from their original position.

● The object which was translated in the −x direction should now translate by in-creasing amounts in the +z direction up to a height of 80. Simultaneously, the object which was translated in the +x direction should translate by the same mag-nitudes in the −z direction down to z = −80. These translations in the z direction should occur with the objects maintaining their new x coordinate.

● This previous step should be reversed, so that the objects return to their original height while maintaining their new x coordinate.

● The objects should return back to their original positions through appropriate trans-lations along the x direction.

To make the movie, you can use successive application of code such as the following:

Please submit shift.m and shift_movie.m