function freierVektor2d

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

clc;
close('all')
deg=pi/180;
global ax
ax=[inf -inf inf -inf];
a=[2;1];
O=[0;0];
P0=[0.1;0.2];
drawPolygon(@plot,[P0 P0+a],'k','linewidth',1.5)
hold('on')
Spitze(P0+a,a,0.5,30*deg);
Schrift(P0+a/2,'\bf\ita','FontSize',54,'HorizontalAlignment','center','VerticalAlignment','bottom','rotation',atan(a(2)/a(1))/deg);
Schrift(P0+[a(1)/2;0],'{\ita}_1','HorizontalAlignment','left','VerticalAlignment','bottom');
Schrift(P0+[a(1);a(2)/2],'_{ }{\ita}_2','HorizontalAlignment','left','VerticalAlignment','middle');
h=0.25;
drawPolygon(@plot,[P0 P0+[a(1);0] P0+a],'--k')
drawPolygon(@plot,[O [0;P0(2)+a(2)+1.5*h]],'k')
drawPolygon(@plot,[O [P0(1)+a(1)+1.5*h;0]],'k')
Spitze([ax(2);0],[1;0],h,45*pi/180)
Schrift([ax(2);0],'\itx','HorizontalAlignment','left','VerticalAlignment','middle');
Spitze([0;ax(4)],[0;1],h,45*pi/180)
Schrift([0;ax(4)],'\ity','HorizontalAlignment','center','VerticalAlignment','bottom');

hold('off')
axis('off')
axis('equal')
axis(ax+0.5*h*[-1 1 -1 1])
print('-depsc','freierVektor2d')

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