% script HOME5 generates the figure for problem 1 of assignment 5, hence,
% incidentally, supplies the data for that problem.

% The following array describes the connectivity of the structure. 
% Each row has three entries, giving (member, joint, joint) .
% In particular, there are 30 members and 12 joints.
m=[
  1  1  4
  2  1  5
  3  1  6
  4  2  5
  5  2  7
  6  2  8
  7  3  8 
  8  3  9
  9  3  6
 10  4  5
 11  4  6 
 12  5  6
 13  5  7
 14  7  8
 15  5  8 
 16  6  8
 17  8  9
 18  6  9
 19  4 12
 20  5 12 
 21  7 12
 22  8 12
 23  9 12
 24  6 12
 25 12 11
 26  7 10
 27  9 10
 28  7 11
 29  9 11
 30 11 10
];

% The next array lists the twelve joints along with their
% (x,y,z)-coordinates:
j=[
  1  0.00  0.00 0.00
  2  6.50  2.15 0.00
  3  6.50 -2.15 0.00
  4 -1.00  0.00 5.54
  5  4.10  1.63 5.54
  6  4.10 -1.63 5.54
  7  7.20  3.26 5.54
  8  7.20  0.00 5.54
  9  7.20 -3.26 5.54
 10 15.86  0.00 6.54
 11  9.83  0.00 7.93
 12  4.50  0.00 8.83];

% set up a particular viewing angle:
al = -1.2;
rot = [cos(al) sin(al) 0
        -sin(al) cos(al) 0
                 0 0 1]; 
xyz = j(:,2:4)*rot;

%  plot the structure:
plot3([xyz(m(:,2),1),xyz(m(:,3),1)]',...
[xyz(m(:,2),2),xyz(m(:,3),2)]',...
[xyz(m(:,2),3),xyz(m(:,3),3)]','w')

hold on
plot3(xyz(:,1), xyz(:,2),xyz(:,3),'*')
%%  note how the next statement labels ALL the joints in one go
text(xyz(:,1)+.5,xyz(:,2),xyz(:,3),num2str((1:12)')); 

% plot a trigon to show the (x,y,z) axes:
trigon=[1 0 0
        0 0 0  
        0 1 0
        0 0 0 
        0 0 1
        1.2 0 0
        0 1.2 0
        0 0 1.2]; trigon = trigon*rot;
f = 3;
plot3(trigon(1:5,1)*f-6,trigon(1:5,2)*f-3,trigon(1:5,3)*f)
%%  note how the next statement labels ALL the axes in one go
text(trigon(6:8,1)*f-6,trigon(6:8,2)*f-3,trigon(6:8,3)*f,['x';'y';'z'])
axis off, axis tight
hold off
print -deps home5.eps
