%%Tower
%MMA Miniproject 4

%%
%First we read the screen size and open a figure window. You can ignore
%these lines.
scrsz = get(0,'ScreenSize');
sz = scrsz(4)/10;

fig = figure('Position',[sz sz 8*sz 8*sz]);

%Then we fix the limits of the axis, and label them x,y,z.
axis([-3 3 -3 3 -3 3]);

xlabel('x')
ylabel('y')
zlabel('z')

%The following data matrix contains the endpoints of the line 
%segments of the tower as its column vectors

D = [-1 -1 -1 -1 1 1 1 1 -1 1 -1 1 -1 1 -1 1 -1 -1 -1 -1 1 1 1 1 1 0 -1 0 -1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 0;
    -1 1 -1 1 -1 1 -1 1 -1 -1 -1 -1 1 1 1 1 -1 -1 1 1 -1 -1 1 1 1 0 1 0 -1 0 -1 0 -0.25 -0.25 -0.25 0.25 0.25 0.25 0 0 0 0.333 0.333 0;
    -1 -1 1 1 1 1 -1 -1 1 1 -1 -1 -1 -1 1 1 -1 1 -1 1 -1 1 -1 1 1 2 1 2 1 2 1 2 -1 0 0 0 0 -1 2 2.5 2.5 2.375 2.375 2.25];

%We plot the tower. Column 1 and 2 of D become the line segment 
%from (-1,-1,-1) to (-1,1,-1). Column 3 and 4 become the line segment
%from (-1,-1,1) to (-1,1,1) and so on.

linesegmentplot(D)

%The program stops, and waits for you to press a key.
pause

%The matrix for a rotation by an angle t about the x-asis is given by
P = @(t) [1 0 0; 0 cos(t) -sin(t); 0 sin(t) cos(t)];

%For t = pi/6, the have

P1 = P(pi/6)

%We rotate the vertices of the tower 30 degrees (pi/6 radians) about 
%the x-asis via matrix multiplication

A=P1*D;

%Then we clear the figure window and plot the result.
cla
linesegmentplot(A)

