function FlaecheGaussK

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

clc;
close('all')
global ax
deg=pi/180;
nEck=inline('repmat(r,2,1).*[cos(t);sin(t)]','r','t');
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);
ax=[min(P(1,:)) max(P(1,:)) min(P(2,:)) max(P(2,:))]+h*[-2 3 -2 2];
[X,Y]=meshgrid(ax(1):h:ax(2),ax(3):h:ax(4));
plot(X,Y,X',Y','color',0.75*[1 1 1]);
hold('on')
[X,Y]=meshgrid(floor(ax(1)):ceil(ax(2)),floor(ax(3)):ceil(ax(4)));
plot(X,Y,X',Y','color',0.75*[1 1 1],'linewidth',2.0);
for x=ceil(ax(1)):floor(ax(2))
  Schrift([x;ax(3)],int2str(x),'FontSize',24,'HorizontalAlignment','center','VerticalAlignment','top');
end
for y=ceil(ax(3)):floor(ax(4))
  Schrift([ax(1),y],[int2str(y) ' '],'FontSize',24,'HorizontalAlignment','right','VerticalAlignment','middle');
end
drawPolygon(@plot,P(:,[1:end 1]),'k','linewidth',1.5)

for k=1:length(t);
  switch k
    case {2,8}
      Schrift(P(:,k),sprintf('{\\itP}_{%d}',k),'HorizontalAlignment','center','VerticalAlignment','top');
    case {3,5}
      Schrift(P(:,k),sprintf('_{ }{\\itP}_{%d}',k),'HorizontalAlignment','left','VerticalAlignment','middle');
    case 4
      Schrift(P(:,k),sprintf('{\\itP}_{%d}',k),'HorizontalAlignment','right','VerticalAlignment','middle');
    case 7
      Schrift(P(:,k),sprintf('{\\itP}_{%d}^{ }',k),'HorizontalAlignment','center','VerticalAlignment','middle');
    case 9
      Schrift(P(:,k),sprintf('{\\itP}_{%d}^{ }',k),'HorizontalAlignment','right','VerticalAlignment','middle');
    case 10
      Schrift(P(:,k),sprintf('{\\itP}_{%d}',k),'HorizontalAlignment','center','VerticalAlignment','middle');
    case 12
      Schrift(P(:,k),sprintf('{\\itP}_{%d   }',k),'HorizontalAlignment','center','VerticalAlignment','top');
    case {1,6,11}
      Schrift(P(:,k),sprintf('{\\itP}_{%d}',k),'HorizontalAlignment','left','VerticalAlignment','top');
    otherwise
      Schrift(P(:,k),sprintf('{\\itP}_{%d}^{ }',k),'HorizontalAlignment','left','VerticalAlignment','top');
  end
end
plot(ax(1:2),[0 0],'k',[0 0],ax(3:4),'k')
Spitze([ax(2);0],[1;0],h,45*pi/180)
Schrift([ax(2);0],'\itx','HorizontalAlignment','right','VerticalAlignment','bottom');
Spitze([0;ax(4)],[0;1],h,45*pi/180)
Schrift([0;ax(4)+h],'_{  }\ity','HorizontalAlignment','left','VerticalAlignment','top');

hold('off')
axis('equal')
axis(ax)
axis('off')
print('-depsc','FlaecheGaussK')

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',30,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

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
