function DreieckA

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
phi=[0:360]*deg;

A=[0;0];
c=[50;0];
b=[10;23];

B=A+c;
C=A+b;
Polygon([A B C A],'k','linewidth',2.0);
hold('on');
vA=AWH(A,B,C);
vB=AWH(B,C,A);
vC=AWH(C,A,B);
Ma=SchnittGerGer(B,B+vB,C,C+vC);
Mb=SchnittGerGer(A,A+vA,C,C+vC);
Mc=SchnittGerGer(A,A+vA,B,B+vB);
StreckeRelOffset(Ma,Mb,0.1,'k','Linewidth',0.25);
StreckeRelOffset(Mb,Mc,0.1,'k','Linewidth',0.25);
StreckeRelOffset(Mc,Ma,0.1,'k','Linewidth',0.25);
StreckeRelOffset(Lotfuss(A,B,Ma),Lotfuss(A,B,Mb),0.2,'k','Linewidth',0.25);
StreckeRelOffset(Lotfuss(B,C,Mb),Lotfuss(B,C,Mc),0.2,'k','Linewidth',0.25);
StreckeRelOffset(Lotfuss(C,A,Ma),Lotfuss(C,A,Mc),0.2,'k','Linewidth',0.25);
Kreisbogen(Lotfuss(B,C,Mc),Mc,Lotfuss(A,C,Mc),30*deg,'k','Linewidth',1.0);
Kreisbogen(Lotfuss(A,C,Ma),Ma,Lotfuss(A,B,Ma),30*deg,'k','Linewidth',1.0);
Kreisbogen(Lotfuss(B,A,Mb),Mb,Lotfuss(B,C,Mb),30*deg,'k','Linewidth',1.0);
hold('off')
axis('equal')
axis(ax)
axis('off')
print('-deps','DreieckA');

function H=Lotfuss(A,B,C);
syms('t','real');
v=B-A;
H=A+double(solve(v'*(A+t*v-C),t))*(B-A);

function v=AWH(A,B,C)
syms('t','real');
alpha1=cart2pol(A(1)-B(1),A(2)-B(2));
alpha2=cart2pol(C(1)-A(1),C(2)-A(2));
alpha=(alpha1+alpha2)/2;
v=[cos(alpha);sin(alpha)];

function S=SchnittGerGer(A,B,C,D)
syms('t','real');
n=[C(2)-D(2);D(1)-C(1)];
S=A+double(solve(n'*(A+t*(B-A)-C),t))*(B-A);

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 StreckeRelOffset(A,B,offset,varargin)
Polygon([A-offset*(B-A) B+offset*(B-A)],varargin{:})

function 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));
Polygon(repmat(M,size(t))+r*[cos(t);sin(t)],varargin{:});
