function det2d

% http://geometrie.hs-nb.de/MATLAB-Programme/det2d.m   Bearbeitungsstand: 18.10.2004
% (C) Martin Nitschke, nitschke@hs-nb.de

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
a=[4;1];
b=[5;4];
c=a+b;
hold('on')
fill([0 b(1) b(1) 0],[b(2) b(2) a(2)+b(2) a(2)+b(2)],0.75*[1 1 1],'EdgeColor','none')
Schrift([b(1)/2;b(2)+a(2)/2],'{\itb}_1{\ita}_2',...
  'HorizontalAlignment','center','VerticalAlignment','middle')
fill(b(1)+[0 a(1) 0],b(2)+[0 a(2) a(2)],0.8125*[1 1 1],'EdgeColor','none')
Schrift([b(1)+a(1)/2;a(2)+b(2)],'{\ita}_1{\ita}_2/2_{    }',...
  'HorizontalAlignment','right','VerticalAlignment','top')
fill([0 a(1) a(1)],[0 0 a(2)],0.8125*[1 1 1],'EdgeColor','none')
Schrift([a(1)/2;0],'_{    }{\ita}_1{\ita}_2/2',...
  'HorizontalAlignment','left','VerticalAlignment','bottom')
fill([0 b(1) 0],[0 b(2) b(2)],0.875*[1 1 1],'EdgeColor','none')
Schrift([b(1)/2;b(2)/2],'{\itb}_1{\itb}_2/2_{  }',...
  'HorizontalAlignment','right','VerticalAlignment','bottom')
fill(a(1)+[0 b(1) b(1)],a(2)+[0 0 b(2)],0.875*[1 1 1],'EdgeColor','none')
Schrift(a+[b(1)/2;b(2)/2],'_{  }{\itb}_1{\itb}_2/2',...
  'HorizontalAlignment','left','VerticalAlignment','top')
fill(a(1)+[0 b(1) b(1) 0],[0 0 a(2) a(2)],0.75*[1 1 1],'EdgeColor','none')
Schrift([a(1)+b(1)/2;a(2)/2],'{\itb}_1{\ita}_2',...
  'HorizontalAlignment','center','VerticalAlignment','middle')
Schrift(c/2,'{\itV}({\bf\ita},{\bf\itb})',...
  'FontSize',30,'HorizontalAlignment','center','VerticalAlignment','middle')

Polygon([[0;0] a c],'k','linewidth',1.5)
Polygon([[0;0] b c],'k','linewidth',1.5)
Spitze(a,a,0.5,20*deg);
Spitze(a+b,b,0.5,20*deg);
Spitze(b,b,0.5,20*deg);
Spitze(b+a,a,0.5,20*deg);
Schrift(a/2,'\bf\ita','HorizontalAlignment','center','VerticalAlignment','bottom','rotation',atan2(a(2),a(1))/deg)
Schrift(a+b/2,'\bf\itb','HorizontalAlignment','center','VerticalAlignment','bottom','rotation',atan2(b(2),b(1))/deg)
Schrift(b/2,'\bf\itb','HorizontalAlignment','center','VerticalAlignment','top','rotation',atan2(b(2),b(1))/deg)
Schrift(b+a/2,'\bf\ita','HorizontalAlignment','center','VerticalAlignment','top','rotation',atan2(a(2),a(1))/deg)
[xTck xI]=unique([0 a(1) b(1) a(1)+b(1)]);
[yTck yI]=unique([0 a(2) b(2) a(2)+b(2)]);
xTckLbl={'' '{\ita}_1' '{\itb}_1' '{\ita}_1+{{\itb}_1}'};
xTckLbl=xTckLbl(xI);
yTckLbl={'' '{\ita}_2' '{\itb}_2' '{\ita}_2+{{\itb}_2}'};
yTckLbl=yTckLbl(yI);
set(gca,'xTick',xTck);
set(gca,'yTick',yTck);
set(gca,'xTickLabel','');
set(gca,'yTickLabel','');
[X,Y]=meshgrid(xTck,yTck);
plot(X,Y,X',Y','color',0.5*[1 1 1])
hold('off')
for k=1:length(xTck)
  Schrift([xTck(k);0],xTckLbl(k),'HorizontalAlignment','center','VerticalAlignment','top')
end
for k=1:length(yTck)
  Schrift([0;yTck(k)],[yTckLbl{k} '_{ }'],'HorizontalAlignment','right','VerticalAlignment','middle')
end
Schrift([0;0],'0','HorizontalAlignment','right','VerticalAlignment','top')
axis('equal')
axis(ax)
print('-depsc','det2d')

function Polygon(P,varargin);
global ax
plot(P(1,:),P(2,:),varargin{:})
if min(P(1,:))<ax(1)
  ax(1)=min(P(1,:));
end
if max(P(1,:))>ax(2)
  ax(2)=max(P(1,:));
end
if min(P(2,:))<ax(3)
  ax(3)=min(P(2,:));
end
if max(P(2,:))>ax(4)
  ax(4)=max(P(2,:));
end

function Schrift(P,txt,varargin)
text(P(1),P(2),txt,'FontName','TimesNewRoman','FontSize',24,varargin{:});

function Spitze(P,v,L,phi);
if nargin<=2
  L=1;
end
if nargin<=3
  phi=7.5*pi/180;
end
ta=tan(phi/2);
v=L*v./repmat(sqrt(dot(v,v)),size(P,1),1);
n=[-v(2,:);v(1,:)];
Q=P-v+ta*n;
R=P-v-ta*n;
for k=1:size(P,2);
  fill([P(1,k) Q(1,k) R(1,k)],[P(2,k) Q(2,k) R(2,k)],'k')
end