function PunktPlusVektor

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

clc;
close('all')
global ax
ax=[inf -inf inf -inf];
deg=pi/180;
a=[-1;1];
b=[8;2];
c=b-a;
hold('on')
Polygon([a b],'k')
Spitze(b,c,0.7,20*deg);
Schrift(a,'\itP','HorizontalAlignment','center','VerticalAlignment','bottom')
Schrift(b,'_{ }{\itP}+{\it\bfv}','HorizontalAlignment','left','VerticalAlignment','baseline')
Schrift(a+c/2,'{\it\bfv}','HorizontalAlignment','center','VerticalAlignment','bottom',...
  'rotation',atan2(c(2),c(1))/deg)
hold('off')
axis('off')
axis('equal')
axis(ax)
print('-depsc','PunktPlusVektor')


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',32,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;
Polygon([P Q R],'k')
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