Graphical Transformations I

pts = [ 0 0 0 1 NaN NaN 0.5 1 1 0 1.5 1]';Note that we end it with a transpose (') to make it 2 by M and with a semicolon so that it won't be printed out.

Once you have all the points typed in, save it as *myfig.m*.

Now to test it. Go to the command window and type *myfig*.
This should load your data into MATLAB. If you have any problems, it
may be that either you didn't save it or that you saved it where
MATLAB can't find it. If you didn't save it, go back and save it.
If MATLAB can't find it, you'll have to change your workspace (use the
... button at the top of the command window).

Now we can plot your name using

plot(pts(1,:),pts(2,:))You should see your figure. If you don't like what you see, go back and change your myfig.m file. If you want to get fancy, you can change the color and line width around using

plot(pts(1,:),pts(2,:),'Color',[0.3 0.8 0.2],'LineWidth',2)where the numbers after the keyword Color are the RGB values (0<=v<1) and the number after LineWidth is the width. If you repeatedly use a certain plot command, you might want to make a function out of it, like this:

function myplot(pts) % my hairy plotter plot(pts(1,:),pts(2,:),'Color',[0.3 0.8 0.2],'LineWidth',2) hold on plot(pts(1,:),pts(2,:),'k*') hold offCopy this to a new M-file and save as

**Once you have myfig.m the way you want it, you should email the file
to yourself or save it by some other means as we will be using it
again tomorrow.**

function newpts = transform(pts,T) % applies the (homogeneous) transformation T to the points in pts M = size(pts,2); % number of points pts = [pts;ones(1,M)]; % add 1s as 3rd coordinate newpts = T*pts; % apply T newpts = newpts(1:2,:); % strip off 3rd coordinateAfter you have saved the function, try this

T = [2 0 0; 0 2 0; 0 0 1]; myfig np = transform(pts,T); plot(pts(1,:),pts(2,:)) hold on plot(np(1,:),np(2,:),'r') hold offYou should see your name twice, once in blue and once twice the original size in red. The commands

Translation: *T = [1 0 tx; 0 1 ty; 0 0 1];*

Rotations: *T = [cos(th) -sin(th) 0; sin(th) cos(th) 0; 0 0 1];*

(Note: **th** must be in radians: radians = degrees*pi/180)

Scaling: *T = [sx 0 0;0 sy 0; 0 0 1];*

Reflection: *T = [1 0 0;0 -1 0;0 0 1];*

T1 =[1 0 1; 0 1 -1; 0 0 1]; T2 = [cos(pi/3) -sin(pi/3) 0; sin(pi/3) cos(pi/3) 0; 0 0 1]; T3 = [2 0 0;0 0.5 0; 0 0 1]; CT = T3*inv(T1)*T2*T1;This translates (x+1,y-1), rotates 60 degrees, translates back (x-1,y+1) and then scales (x*2, y*0.5)

If you are too lazy to make a transformation this way you can create
random transformations by *Tr = [randn(2,3); 0 0 1];*

2. Create a transformation representing a translation and a rotation (you can choose the values and the order). Plot your name and copies of your name after the transformation has been applied 1, 2, 3 and 4 times.

3. Construct 3 different basic transformations of 3 different types. Construct the 6 different complex transformations formed by applying the 3 basics in all the possible different orders, for example T123 = T1*T2*T3, T132 = T1*T3*T2, etc. Plot your name and copies of your name under each of these 6 transformations.

After you figure out what pictures you want in your movie, you need to figure out what screen (or axes) will hold all your pictures. Figure out the x-range and the y-range that can contain every picture you draw. Create a vector of these values:

myaxis = [xleft xright ybot ytop];

Now you are ready to make a movie. The steps are pretty basic, first you create the space for the movie, then you create images frame by frame and save them. It looks like this:

n = 24; % number of frames (you can use more or less) axis(myaxis) M = moviein(n); for j=1:n % put your plot commands here, before the axis command axis(myaxis) M(:,j) = getframe; % captures whatever is on the graph endThe command axis off removes the axis markings.

To play your movie, you just type
*movie(M)* or *movie(M,10)* or
*movie(M,-10)*.
The first version plays it once, the second 10 times, the third plays
it forward and backward.