function UmfangVieleck

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

clc;
close('all')
global ax
deg=pi/180;
verschieb=inline('P+repmat(v,1,size(P,2))','P','v');
nEck=inline('repmat(r,2,1).*[cos(t);sin(t)]','r','t');
ax=[inf -inf inf -inf];
t=linspace(0,2*pi,12);
Q=nEck(3+cos(5.2*t),t);
h=0.2;
P=h*round(Q(:,[1:3 5 4 6:end])/h);
drawPolygon(@plot,P(:,[1:end 1]),'k','linewidth',1.5)
hold('on')

for k=1:length(t)
  if k==1
    v=P(:,k)-P(:,end);
  else
    v=P(:,k)-P(:,k-1);
  end
  Schrift(P(:,k)-0.5*v,sprintf('{\\ita}_{%d}',k),'FontSize',24,...
    'Rotation',Rot([0;0],v),'HorizontalAlignment','center','VerticalAlignment','top');
end
ax=ax+h*[-1 1 -1 1];

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

function H=W(A,B,C)
syms('t','real');
alpha1=cart2pol(B(1)-A(1),B(2)-A(2));
alpha2=cart2pol(C(1)-A(1),C(2)-A(2));
alpha=(alpha1+alpha2)/2;
n=[-sin(alpha);cos(alpha)];
H=B+double(solve(n'*(B+t*(C-B)-A),t))*(C-B);

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',15,varargin{:});

function r=Rot(a,b)
deg=pi/180;
r=atan2(b(2)-a(2),b(1)-a(1))/deg;
if r<0
  r=r+180;
end
if r>90
  r=r-180;
end
