function VektorMinusVektor

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
a=[8;2];
b=[-1;1];
c=a+b;
Polygon([[0;0] a],'k','linewidth',1.5)
hold('on')
Polygon([[0;0] b],'k','linewidth',1.5)
Polygon([b a],'k','linewidth',1.5)
Polygon([b c a],'k')
Spitze(a,a,0.5,20*deg);
Spitze(b,b,0.5,20*deg);
Spitze(b,b-a,0.5,20*deg);
Schrift(a/2,'\bf\ita','HorizontalAlignment','center','VerticalAlignment','top','rotation',atan2(a(2),a(1))/deg)
Schrift(b/2,'\bf\itb','HorizontalAlignment','center','VerticalAlignment','top','rotation',atan2(b(2),b(1))/deg+180)
Schrift(c/2,'{\bf\itc} = {\bf\itb}-{\bf\ita}','HorizontalAlignment','center','VerticalAlignment','bottom',...
  'rotation',atan2(b(2)-a(2),b(1)-a(1))/deg+180)
hold('off')
axis('off')
axis('equal')
axis(ax)
print('-depsc','VektorMinusVektor')


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 Schrift(P,txt,varargin)
text(P(1),P(2),txt,'FontName','TimesNewRoman','FontSize',30,varargin{:});

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