function FlaecheParallelogramm

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
a=[11;0];
b=[3;7];
n=[-a(2);a(1)]/norm(a);
h=n*n'*b;
A=[0;0];
drawPolygon(@fill,[A A+a A+a+h A+h],0.875*[1 1 1],'EdgeColor',0.875*[1 1 1],'EraseMode','xor')

hold('on')
PolygonM([A   A+b   A+h     A],0.4,'o','color',0.0*[1 1 1],'EraseMode','xor','MarkerSize',7)
PolygonM([A+a A+a+h A+a+b A+a],0.4,'o','color',0.0*[1 1 1],'EraseMode','xor','MarkerSize',7)
drawPolygon(@plot,[A A+a A+a+b A+b A],'k','linewidth',1.5,'EraseMode','xor')
hold('off')

Schrift(A+a/2,'\itg','HorizontalAlignment','center','VerticalAlignment','top');
Schrift(A+a+h/2,'\ith','erase','xor',...
  'HorizontalAlignment','center','VerticalAlignment','bottom','Rotation',90);
axis('equal')
axis(ax)
axis('off')
print('-depsc','FlaecheParallelogramm');

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 PolygonM(P,d,varargin)
for k=2:size(P,2)
  v=P(:,k)-P(:,k-1);
  t=linspace(0,1,round(norm(v)/d));
  drawPolygon(@plot,repmat(P(:,k-1),1,length(t))+repmat(t,length(P(:,k-1)),1).*repmat(v,1,length(t)),varargin{:})
end

function Schrift(P,txt,varargin)
text(P(1),P(2),txt,'FontName','TimesNewRoman','FontSize',40,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
