function Vierecke

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
A=[0;0]; B=[7;0]; C=[13;7]; D=[3;8];
a=B-A; b=C-B; c=D-C; d=A-D; 
Polygon([A B C D A],'k','linewidth',1.5)
hold('on')

A(2)=A(2)+1.05*d(2); B=A+a; C=B+b; D=B+2*(Lotfuss(A,C,B)-B);
Polygon([A B C D A],'k','linewidth',1.5)
Polygon([A C],'k','linewidth',0.25)
Polygon([B D],'k','linewidth',0.25)

A(2)=A(2)+1.05*d(2); B=A+a; C=B+b; D=C+a*a'*c/(a'*a);
Polygon([A B C D A],'k','linewidth',1.5)

A(2)=A(2)+1.05*d(2); B=A+a; C=B+b; D=C-a;
Polygon([A B C D A],'k','linewidth',1.5)

bRe=norm(b)*[-a(2);a(1)]/norm(a);
A=[(ax(1)+ax(2)-a(1))/2;A(2)-1.1*bRe(2)]; B=A+a; C=B+bRe; D=C-a;
Polygon([A B C D A],'k','linewidth',1.5)

bRau=norm(a)*b/norm(b);
A(2)=A(2)-1.2*bRau(2); B=A+a; C=B+bRau; D=C-a;
Polygon([A B C D A],'k','linewidth',1.5)

bQu=[-a(2);a(1)];
A(2)=A(2)-1.1*bQu(2); B=A+a; C=B+bQu; D=C-a;
Polygon([A B C D A],'k','linewidth',1.5)

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

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 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
