% Zeichnen eines 2D-Fachwerks
function drawtorsmod (xy , km , kr , bk , adds)

[nk,nn] = size (xy) ;
[ne,ke] = size (km) ;

% Elemente:
n = 6 ;
x = zeros (n,1) ;
y = zeros (n,1) ;

for i=1:ne
   xmid = 0 ;
   ymid = 0 ;
   for j=1:n
      k    = km(i,j) ;
      if (j<4) m = j*2-1 ; else m = (j-3)*2 ; end
      x(m) = xy(k,1) ;
      y(m) = xy(k,2) ;
      xmid = xmid + xy(k,1) ;
      ymid = ymid + xy(k,2) ;
   end
   fill (x , y , 'y') ;
   if nargin > 4 & strfind(adds,'e') ~= []
     text (xmid/n , ymid/n , int2str(i) , 'Color' , 'r') ;
   end
   hold on ;
end

% Knoten:
plot (xy(:,1) , xy(:,2) , 'ro') ;
if nargin > 4 & strfind(adds,'k') ~= []
  for i=1:nk
    text (xy(i,1) , xy(i,2) , int2str(i) , 'Color' , 'b' , 'HorizontalAlignment' , 'Right') ;
  end
end
hold on ;

% Vorbereitung fuer Lager und Kraefte:
minx = min (xy(:,1)) ;
maxx = max (xy(:,1)) ;
miny = min (xy(:,2)) ;
maxy = max (xy(:,2)) ;
ranx = (maxx-minx)*0.2 ;
rany = (maxy-miny)*0.2 ;
lagh = (ranx+rany)/6 ;
minr = min(ranx,rany)*1.5 ;
fwid = minr/20 ;

% Lager:
for i=1:nk
    if (kr(i) == 1) 
       plot (xy(i,1) , xy(i,2) , 'go') ;
       hold on ;
    end 
end

axis ([minx-ranx maxx+ranx miny-rany maxy+rany]) ;
axis equal ;
