function VektorMinusVektor

% http://geometrie.hs-nb.de/MATLAB-Programme/SkalarMalVektor.m   Bearbeitungsstand: 17.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];
L=0.8;
phi=45*deg;
offs=2*[-a(2);a(1)]/norm(a)*L;
hold('on')
Q=[-0.4 -1 2 0.5 1];
for q=1:length(Q)
  Polygon([(q-1)*offs+[0;0] (q-1)*offs+Q(q)*a],'k','linewidth',1.5)
  Spitze((q-1)*offs+Q(q)*a,Q(q)*a,L,phi);
  if Q(q)>0
    if abs(Q(q)-1)<sqrt(eps)
      Schrift((q-1)*offs+Q(q)*a,'\bf\ita_{ }',...
        'HorizontalAlignment','right','VerticalAlignment','middle','rotation',atan2(a(2),a(1))/deg+180)
    else
      Schrift((q-1)*offs+Q(q)*a,strrep(sprintf('%g%s',Q(q),'\bf\ita_{ }'),'.',','),...
        'HorizontalAlignment','right','VerticalAlignment','middle','rotation',atan2(a(2),a(1))/deg+180)
    end
  else
    if abs(Q(q)+1)<sqrt(eps)
      Schrift((q-1)*offs+Q(q)*a,'_{ }-\bf\ita',...
        'HorizontalAlignment','left','VerticalAlignment','middle','rotation',atan2(a(2),a(1))/deg+180)
    else
      Schrift((q-1)*offs+Q(q)*a,strrep(sprintf('_{ }%g%s',Q(q),'\bf\ita'),'.',','),...
        'HorizontalAlignment','left','VerticalAlignment','middle','rotation',atan2(a(2),a(1))/deg+180)
    end
  end
end
hold('off')
axis('off')
axis('equal')
axis(ax)
print('-depsc','SkalarMalVektor')


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