%
%  macm 202 -- 11 mar 03 -- djm
%
%  w10make.m:  truss design tool

%  grid generator

x = -3:0.5:3;
y =  0:0.5:10;

[xg,yg] = meshgrid(x,y);

figure(10);clf
plot(xg(:),yg(:),'k.')
hold on
title('\bf truss builder')
axis equal
axis([-3.5 3.5 -0.5 10.5])

%  empty nodegrid

nodes = [];

%  click on points

disp('start clicking, return to stop')
count = 0;  more = 1;  shift = 1/8;
while (more==1)
  [x1,y1] = ginput(1);
  if (isempty(x1)==0)
      x2 = 0.5*round(2*x1);
      y2 = 0.5*round(2*y1);
      disp(['node = (' num2str([x2 y2]) ')'])
      plot(x2,y2,'r.')
      count = count + 1;
      text(x2+shift,y2+shift,num2str(count),'color','r')
      nodes = [nodes ; x2 y2];
  else
      more = 0;
  end
end
disp(['# of nodes x 2= ' num2str(2*count)])

%  connect the dots

join = zeros(count,count);  base = 1;
base = round(input('choose node # (0=done):'));

while (base~=0)
    connects = round(input('join list, [# # #]:'));
    for j=1:size(connects,2)
        big = max([base,connects(j)]);
        sma = min([base,connects(j)]);
        join(sma,big)=1;
        plot([nodes(sma,1) nodes(big,1)], ...
             [nodes(sma,2) nodes(big,2)],'b')
    end
    disp(' ')
    disp(['# of nodes  x 2  = ' num2str(2*count)])
    disp(['# of struts + 3 = '  num2str(3+sum(join(:)))])
    base = round(input('choose node # (0=done):'));
end

save truss0 nodes join