GS 2001/Math - Collins
Lab 6
Graphical Transformations - The Name Game, Part 2

Preliminaries

Start MATLAB (from Start Menu).
Arrange your windows so you can see MATLAB and this webpage.
If it is not already on your computer, copy your "name.m" file
from your floppy to the work folder in MATLABR11 on the C: drive.

Load the Programs

You will need the programs "viewname.m" and "viewname2.m", so
if you don't have them on the computer, you can copy them from
below into M-files.

viewname.m

function viewname(N)
% plots the name as given in the data in N
%  each row of N has: segment #, length, angle, x,y coord.

LS = [0 1; 0 0; 1 1];   % line segement from (0,0) to (1,0);
Nseg = size(N,1);   % number of segments

for i = 1:Nseg
   sx = N(i,2);        % length
   sy = sx;
   a  = N(i,3);        % angle
   a  = a*pi/180;      % convert to radians (if you used degrees)
   tx = N(i,4);        % coordinates
   ty = N(i,5);

   T = [sx*cos(a) -sy*sin(a) tx; sx*sin(a) sy*cos(a) ty; 0 0 1];
   newS = T*LS;        % transform the segment
   plot(newS(1,:),newS(2,:))   % first row is x coord, 2nd is y
   hold on
end

hold off
axis equal


viewname2.m

function viewname2(N,A)
% plots the name as given in the data in N, transformed by A
%  each row of N has: segment #, length, angle, x,y coord.

LS = [0 1; 0 0; 1 1];   % line segement from (0,0) to (1,0);
Nseg = size(N,1);   % number of segments

for i = 1:Nseg
   sx = N(i,2);        % length
   sy = sx;
   a  = N(i,3);        % angle
   a  = a*pi/180;      % convert to radians (if you used degrees)
   tx = N(i,4);        % coordinates
   ty = N(i,5);

   T = [sx*cos(a) -sy*sin(a) tx; sx*sin(a) sy*cos(a) ty; 0 0 1];
   newS = T*LS;        % transform the segment
   newS = A*newS;
   plot(newS(1,:),newS(2,:))   % first row is x coord, 2nd is y
   hold on
end

hold off
axis equal



After you get these loaded, try the following to make sure it all
works:
   viewname(N), hold on
   a = 30*pi/180;
   rot = [cos(a) -sin(a) 0; sin(a) cos(a) 0; 0 0 1];
   viewname2(N,rot)
You should see your name twice, once regular and once rotated.

Fractal Name

We are going to make changes to viewname so that each segment 
of your name is written using your name.  We will do this by using
the transformations we use to build your name from line
segments as input to viewname2.

First we need to scale your data so that your name is similar
to the line segment of length 1.  Type
   viewname(N)
Determine how long your name is, i.e. how far to the right
does it go?  We need to scale all the lengths and translation
values by the reciprical of this value.  For example, if the
length of your name is 29, you need to scale the values by 1/29.
It would look like this (use your length instead of 29):
   N(:,2) = N(:,2)/29;
   N(:,4) = N(:,4)/29;
   N(:,5) = N(:,5)/29;
Try viewname(N) to see the result.

Now we need to create our fractal name maker.  Open up "viewname.m"
and save it as "fracname.m".  Make the following changes:
    change the function name from "viewname" to "fracname"
    replace the creation and the plotting of the segment
        (newS = T*LS   and plot(...)) with a call to viewname2:
       viewname2(N,T)
That's it.  Save the file and then go to the command window and
type fracname(N)
Notice how in the longer segments the letters are taller.  We
can change this by adjusting the scaling in the y-direction.
Go back to "fracname.m" and change the line "sy = sx;" to "sy = 1/10;".
Save and try fracname(N) again.
You can adjust this value to make the results pleasing.

Exercise 1

Make a nice looking fractal version of your name and print it out
to turn in.  You might try axis off to
remove the axes before you print.

If you want to save it to a file, you can do that from the print menu,
or from the command window:
    print -djpeg filename.jpg
to save it to the file filename.jpg.

Challenge

Write program(s) to make it so each segement of the names that
make up the segments of your name are written with your name.
It may take some time for such a program to run as it has to
draw (M)^3 segments, where M is the original number of segments in
your name.

Exercise 2

Use all the techniques we developed yesterday and today to make
a fancy picture using your name.  You can use fractals of your name,
rotations, translations, shears, etc.  

Remember to use hold on after every plot
command (like "viewname2") to keep the results on the graph
for the next plot.

When you are done print out a copy, save a copy to a file and
e-mail it to me.  I'll put it on our class webpage.

You can use different colors and line styles by adding to the plot command.
Use help plot to see the options.

To make the lines thicker, change the plot command to
    plot(newS(1,:),newS(2,:),'LineWidth',6)
You can change the 6 to other values if you want.

Here's some commands to build some basic transformations:
   shear = [1 0.5 0; 0 1 0; 0 0 1];  % shear of 1/2
   a = 30*pi/180;
   rot = [cos(a) -sin(a) 0; sin(a) cos(a) 0; 0 0 1];  % rot of 30 degrees
   sc  = [0.5 0 0; 0 0.5 0; 0 0 1];   % scale by 1/2
   trans = [1 0 2;0 1 -1; 0 0 1];  % translate 2 right, 1 down  
You can use these alone, create new versions, multiply them
together to make composite transformations, etc.  Go wild!

Use a M-file script to put all your commands in so that
you can make adjustments without having to re-type everything.

If you are uninspired, here's some ideas:
   Use a combination of translate or scale, and rotate
   Use 90 degree rotations, scales by powers of 1/2 and translations
      to make a grid or some other structure using your name
   Figure out how to use different colors

Here's one I did:
 
Mail: ccollins@math.utk.edu