CSE4421 Lab 01

Thu Jan 10 11:30-13:30

Introduction

The purpose of this lab is to ensure that students are familiar with using Matlab for problem solving and programming so that subsequent labs and assignments can be completed successfully.

There are two parts to this lab. The first part is a Matlab tutorial, which must be completed prior to the first lab. The second part is a lab exercise in Matlab that must be submitted at the end of the first lab session.

Before the First Scheduled Lab

Time required: Approximately 2.5 hours

Complete the Matlab tutorial that shows you how to use the Matlab environment, solve problems using Matlab (including publishing Matlab programs to formats such as HTML and PowerPoint), and program in Matlab. It is possible to complete the tutorial without running Matlab, but you should consider running Matlab simultaneously with the tutorial.

If you are familiar with Matlab (creating functions and scripts, programming, problem solving, and publishing Matlab programs to HTML) then you might be able to skip this step. Even if you are familiar with Matlab, you should consider reviewing the tutorial (especially the Publishing Matlab Programs segment).

Otherwise, register for an account with MathWorks at http://www.mathworks.com/academia/student_center/tutorials/register.html and complete the interactive tutorials (MATLAB On-Ramp, MATLAB for Problem Solving, and Programming in MATLAB).

During the Lab

This lab requires you write some Matlab functions, write a Matlab script that uses the functions, and publish the script and its output to HTML.

Geometric Transformations in 2D

A geometric transformation in 2D is a function that maps a 2D point p = x y to a new 2D point q = x ' y ' .

A translation moves all points a constant distance in a given direction. A translation of a point can be accomplished using vector addition:
x ' y ' = x y + t x t y

A vertical shear is a translation along the y axis by an amount that increases linearly with the x component of the point; this transformation will transform a square into a rhomboid (a parallelogram with unequal sides and angles not equal to 90 degrees). A vertical shear by a non-zero scalar amount m can be accomplished using matrix multiplication:
x ' y ' = 1 0 m 1 x y

A rotation about the origin spins a point counterclockwise around the origin through an angle θ. A rotation can be accomplished using matrix multiplication: x ' y ' = cos θ   sin θ sin θ cos θ x y

1. Implement Matlab functions that perform translation, vertical shear, and rotation in 2D. Your functions must have the following signatures:

function Q = translate2(P, t)
function Q = vshear2(P, m)
function Q = rotate2(P, theta)

In each function, P should be a 2 x n matrix of n 2D column vectors representing the points to be transformed, and Q should be a 2 x n matrix of n 2D column vectors representing the output transformed points. For translate2, t is the 2D translation vector. For vshear2, m is the shear amount. For rotate2, theta is the angle in degrees.

2. Write a Matlab script (that will be published as HTML) that uses the three functions you created in Step 1 to transform two objects that are represented as points.

Start by creating a section (cell) in your script with the title Original Shapes. The first object should be a square represented by its corner points 1 1 , - 1 1 , - 1 - 1 , 1 - 1

The second object should be a circle of radius 1 centered at the point 5 0 and represented using points on the circumference of the circle every 10 degrees. Plot the closed outlines of both the square and circle in black using the plot command; both shapes should appear on the same plot (use the hold on command). The square should look like a square (not a rectangle) and the circle should like a circle (not an ellipse); use the axis equal command.

Create a new section (cell) in the script with the title Translation. Next, translate the points of the square and circle using your translate2 function by the vector t = [-3; -3]. Plot the translated square and circle in red on the same plot as the original square and circle (the plot should show the original shapes in black and the transformed shapes in red).

Make sure to use the axis equal command when plotting the shapes in Steps 3-6.

3. Create a new section (cell) in the script with the title Vertical Shear. Use your vshear2 function with a shear amount m = 3 to transform the original shapes. In a new figure, plot the original and transformed shapes in black and red, respectively.

4. Create a new section (cell) in the script with the title Rotation. Use your rotate2 function with an angle theta = 120 degrees to transform the original shapes. In a new figure, plot the original and transformed shapes in black and red, respectively.

5. Create a new section (cell) in the script with the title Translation Followed by Rotation. Translate the original shapes first, and then rotate the translated shapes. Use the same translation and rotation parameters as in Steps 2 and 4. In a new figure, plot the original and final transformed shapes in black and red, respectively.

6. Create a new section (cell) in the script with the title Rotation Followed by Translation. Rotate the original shapes first, and then translate the rotated shapes. Use the same translation and rotation parameters as in Steps 2 and 4. In a new figure, plot the original and final transformed shapes in black and red, respectively.

7. Publish your Matlab script to an HTML file.

8. Submit your Matlab functions, Matlab script, and published HTML file using the command

  submit 4421 L1 <your files>