function trel(barforces, inputforces)
% trel(barforces,inputforces)
% desenha o grafico de uma trelica com as forcas das barras
% representadas pela cor e as forcas nos nós representadas
% pelo comprimento
%
% barforces - vetor 14x1 com os valores de forca de tracao nas
%             barras, compressao se negativo, e as forcas
%             normais Nax, Nay e Ngy nos nós "a" e "g"
%             [v1,v2,v3,v4,v5,v6,v7,Nay,Nax,Ngy]
%
% inputforces - vetor 14x1 com os valores das forcas de entrada
%               aplicadas nos nós
%          [Fax,Fay,Fbx,Fby,Fcx,Fcy,Fdx,Fdy,Fex,Fey,Ffx,Ffy,Fgx,Fgy]


if nargin==0
    barforces=zeros(14,1);
    inputforces=zeros(14,1);
elseif nargin==1
    inputforces=zeros(14,1);
end
if size(barforces,2)==14
    barforces=barforces';
end
if size(inputforces,2)==14
    inputforces=inputforces';
end
if size(barforces,1)~=14 || size(barforces,2)~=1 || ...
        size(inputforces,1)~=14 || size(inputforces,2)~=1
    display('WRONG INPUT SIZE - VECTORS MUST BE 14X1')
    return
end

%node coordinates
c=cos(pi/3); s=sin(pi/3);
p=[0 0; c s; 2*c 0; 3*c s; 4*c 0; 5*c s; 6*c 0; 0 0.5; -0.5 0; 6*c 0.5] +1;

%bars connecting nodes [i j]
m=[1 2; 2 3; 3 4; 4 5; 5 6; 6  7; 1 3; 2 4; 3 5; 4 6; 5 7; 1 8; 1 9; 7 10]';

%forces for each bar
%barforces=[0 0 0 -10 -5 0 5 1 0 -1 0 0 0 0]';
%inputforces=[0 0 3 -4 0 0 0 0 0 0 0 0 0 0 0 0]';

valmax=10;

%plotting
linex=[p(m(1,:),1) p(m(2,:),1)]';
liney=[p(m(1,:),2) p(m(2,:),2)]';
figure
hold on
%make figure fit
axis([0 4.5 0.5 2.0])
axis equal
%draw bars and nodes
bars=plot(linex,liney,'r-','LineWidth',3);
for i=1:size(p,1)
    nodes(i)=plot(p(i,1),p(i,2),'ro','MarkerFace','y');
end
set(nodes(8:10),'Marker','^','MarkerFace','k');
set(nodes(9),'Marker','<');

%write names of the bars
for i=1:11
    x=0.5*p(m(1,i),1)+0.5*p(m(2,i),1);
    y=0.5*p(m(1,i),2)+0.5*p(m(2,i),2);
    text(x+0.05,y,['v',num2str(i)])
end

%set colors of bars
cmap=jet;
for f=1:size(barforces,1)
    c=cmap(1+floor(63*(barforces(f)+valmax)/(valmax*2)),:);
    set(bars(f),'Color',c);
end

%write names of the nodes
for i=1:7
    c='a'-1;
    text(p(i,1)+0.1,p(i,2)+0.1,char(c+i));
end
text(p(8,1)+0.1,p(8,2)+0.1,'Nay');
text(p(9,1)+0.1,p(9,2)+0.1,'Nax');
text(p(10,1)+0.1,p(10,2)+0.1,'Ngy');

%draw input forces
for f=1:size(inputforces,1)
    node=ceil(f/2);
    horiz=rem(f,2);
    if inputforces(f)~=0
        x=p(node,1);
        y=p(node,2);
        if horiz
            dx=inputforces(f)/10; dy=0;
        else
            dy=inputforces(f)/10; dx=0;
        end
        vector=plot([x x+dx],[y y+dy],'k-');
        plot(x+dx,y+dy,'k*')
    end
end

