function Dreieck0sSW

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
phi=20*deg;
co=cos(phi);
si=sin(phi);

A=[0;0];
c=30*[co;si];;
b=[co -si;si co]*[10;23];

B=A+c; 
C=A+b; 
a=C-B; 
alpha=acos(b'*c/(norm(b)*norm(c)));
Polygon([A C],'k','linewidth',1.5);
hold('on');

Polygon([C B],'k','linewidth',0.25);
Kreisbogen(C-0.1*norm(c)*b/norm(b),C,C-0.1*norm(c)*a/norm(a),0,'k','linewidth',1.5)
B=A+0.6*norm(b)*c/norm(c);
Kreisbogen(B,A,B,phi,'k','linewidth',0.25);

A(1)=A(1)+1.05*norm(c); 
C=A+b; 
gamma=55*deg;
B=C+norm(a)*[cos(phi+alpha-pi+gamma);sin(phi+alpha-pi+gamma)]; 
a=C-B;
Polygon([A C],'k','linewidth',1.5);
r=0.85*norm(b);
B=SchnittGerKr(C,a,A,r);
Polygon([C B(:,1)],'k','linewidth',0.5);
Polygon([B(:,1) B(:,1)-0.1*(C-B(:,1))],'k','linewidth',0.25);
Polygon([B(:,1) A B(:,2)],'--k','linewidth',0.5)
Kreisbogen(C-0.1*norm(c)*b/norm(b),C,C-0.1*norm(c)*a/norm(a),0,'k','linewidth',1.5)
Kreisbogen(B(:,1),A,B(:,2),7.5*deg,'k','linewidth',0.25);

A(1)=A(1)+1.05*norm(A-B(:,1)); 
C=A+b; 
gamma=asin(r/norm(b))
B=C+norm(a)*[cos(phi+alpha-pi+gamma);sin(phi+alpha-pi+gamma)]; 
a=C-B;
Polygon([A C],'k','linewidth',1.5);
B=SchnittGerKr(C,a,A,r);
Polygon([C B(:,1)],'k','linewidth',0.5);
Polygon([B(:,1) B(:,1)-0.5*(C-B(:,1))],'k','linewidth',0.25);
Polygon([B(:,1) A B(:,2)],'k','linewidth',0.5)
Kreisbogen(C-0.1*norm(c)*b/norm(b),C,C-0.1*norm(c)*a/norm(a),0,'k','linewidth',1.5)
Kreisbogen(B(:,1),A,B(:,2),15*deg,'k','linewidth',0.25);

hold('off')
axis('equal')
axis(ax)
axis('off')
print('-deps','Dreieck0sSW');

function S=SchnittGerKr(A,v,M,r)
syms('t','real');
n=[-v(2);v(1)];
tS=sort(double(solve((M-A-t*v)'*(M-A-t*v)-r^2,t)));
S=[A+tS(1)*v A+tS(2)*v];

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 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{:});
