function det2dgh

% http://geometrie.hs-nb.de/MATLAB-Programme/det2dgh.m   Bearbeitungsstand: 17.8.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];
fill([0 a(1) a(1)+b(1) b(1)],[0 a(2) a(2)+b(2) b(2)],0.875*[1 1 1])
hold('on')
Polygon([[0;0] a a+b],'k','linewidth',1.5)
Polygon([[0;0] b a+b],'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','bottom','rotation',atan2(b(2),b(1))/deg)
Schrift(b+a/2,'\bf\ita','HorizontalAlignment','center','VerticalAlignment','bottom','rotation',atan2(a(2),a(1))/deg)
Schrift((a+b)/2,'{\itV}({\bf\ita},{\bf\itb})^{  }',...
  'FontSize',30,'HorizontalAlignment','center','VerticalAlignment','middle')
a0=a/norm(a);
H=a0*a0'*b;
Polygon([b H],'k')
Polygon([a 1.5*H-0.5*a],'k')
Schrift([0;0],'       \alpha','HorizontalAlignment','left','VerticalAlignment','middle',...
  'rotation',(atan2(a(2),a(1))+atan2(b(2),b(1)))/2/deg)
Schrift(a/2,'{\it g}=|{\bf\ita}|','HorizontalAlignment','center','VerticalAlignment','top',...
  'rotation',atan2(a(2),a(1))/deg)
Schrift((b+H)/2,'{\ith} = |{\it\bfb}| sin \alpha','HorizontalAlignment','center','VerticalAlignment','bottom',...
  'rotation',180+atan2(b(2)-H(2),b(1)-H(1))/deg)
b0=b/norm(b);
Kreisbogen(1.3*a0,[0;0],1.3*b0,0,'k')
hold('off')
axis('off')
axis('equal')
axis(ax)
print('-depsc','det2dgh')

function P=Kreisbogen(A,M,B,offset,varargin)
deg=pi/180;
[t1,r1]=cart2pol(A(1)-M(1),A(2)-M(2));
[t2,r2]=cart2pol(B(1)-M(1),B(2)-M(2));
if abs(r1-r2)>sqrt(eps)
  error('Kreisbogen: A und B liegen nicht auf einem Kreis mit Mittelpunkt M')
end
r=(r1+r2)/2;
t1=t1-offset;
t2=t2+offset;
if t2<t1
  t2=t2+2*pi;
end
t=linspace(t1,t2,round((t2-t1)/deg));
P=repmat(M,size(t))+r*[cos(t);sin(t)];
Polygon(P,varargin{:});


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