function det3d

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

% Ausserdem benötigt: geometrie.hs-nb.de/Bilder/rechteHand.JPG

global ax
deg=pi/180;
close('all')
A=imread('rechteHand.jpg');
image(A)
ax=[1 size(A,2) 1 size(A,1)];

O=[587;651];
hold('on');
O=[618.1579; 592.9649];
a=[502.0611;  92.1537];
b=[ 84.7718; 297.4120];
c=[ 68.1982; 496.2957];
drawPolygon(@plot,[O a],'k','linewidth',2.0)
drawPolygon(@plot,[O b],'k','linewidth',2.0)
drawPolygon(@plot,[O c],'k','linewidth',2.0)
drawPolygon(@plot,[a a+b-O b O],'k');
drawPolygon(@plot,[a a+c-O c O],'k');
drawPolygon(@plot,[b b+c-O c O],'k');
drawPolygon(@plot,[a-O+b a+b+c-2*O a-O+c a],'k');
drawPolygon(@plot,[b+c-O a+b+c-2*O],'k');
h=10;
Spitze(a,a-O,50,45*pi/180);
Spitze(b,b-O,50,45*pi/180);
Spitze(c,c-O,50,45*pi/180);
Schrift((O+a)/2,'\bf\ita','HorizontalAlignment','center','VerticalAlignment','bottom',...
  'rotation',atan2(O(1)-a(1),O(2)-a(2))/deg-90)
Schrift((O+b)/2,'\bf\itb','HorizontalAlignment','center','VerticalAlignment','bottom',...
  'rotation',atan2(O(1)-b(1),O(2)-b(2))/deg-90)
Schrift((O+c)/2,'\bf\itc','HorizontalAlignment','center','VerticalAlignment','top',...
  'rotation',atan2(O(1)-c(1),O(2)-c(2))/deg-90)

hold('off');

axis('equal')
axis('off')
axis(ax)
print('-deps','det3d')

function drawPolygon(draw,P,varargin);
global ax
feval(draw,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',21,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
