function StreckeStrahlGerade

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

global ax
ax=[inf -inf inf -inf];
close('all')
deg=pi/180;
A=[0;0];
a=0.5;
b=1.3;
h=0.3;
v=[11;4];
v=v/norm(v);

figure('numbertitle','off','name','Strecke');
drawPolygon(@plot,A,'.k','Markersize',30,'color',0.5*[1 1 1]');
hold('on')
n=0.25*h*[-v(2);v(1)];
drawPolygon(@plot,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'color',0.5*[1 1 1]);
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg,0.5*[1 1 1]);
Schrift(A+0.5*a*v-n,'\it\bfv','color',0.5*[1 1 1],'Rotation',atan2(v(2),v(1))/deg,'HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot,[A+a*v A+b*v],'.k','Markersize',30);
drawPolygon(@plot,[A-h*v A+a*v],'color',0.5*[1 1 1]);
drawPolygon(@plot,[A+a*v A+b*v],'k','linewidth',2.0);
drawPolygon(@plot,[A+b*v A+(b+h)*v],'color',0.5*[1 1 1]);
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','bottom','color',0.5*[1 1 1])
Schrift(A+a*v,'{\itP}_0+{\ita\bfv}_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(A+b*v,'{\itP}_0+{\itb\bfv}_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','StreckeStrahlGerade-1')

figure('numbertitle','off','name','Strahl');
drawPolygon(@plot,A,'.k','Markersize',30,'color',0.5*[1 1 1]);
hold('on')
n=0.25*h*[-v(2);v(1)];
drawPolygon(@plot,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'color',0.5*[1 1 1]);
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg,0.5*[1 1 1]);
Schrift(A+0.5*a*v-n,'\it\bfv','color',0.5*[1 1 1],'Rotation',atan2(v(2),v(1))/deg,'HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot,A+a*v,'.k','Markersize',30);
drawPolygon(@plot,[A-h*v A+a*v],'color',0.5*[1 1 1]);
drawPolygon(@plot,[A+a*v A+(b+h)*v],'k','linewidth',2.0);
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','bottom','color',0.5*[1 1 1])
Schrift(A+a*v,'{\itP}_0+{\ita\bfv}_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','StreckeStrahlGerade-2')

figure('numbertitle','off','name','Gerade');
drawPolygon(@plot,A,'.k','Markersize',30);
hold('on')
n=0.25*h*[-v(2);v(1)];
drawPolygon(@plot,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'color',0.5*[1 1 1]);
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg,0.5*[1 1 1]);
Schrift(A+0.5*a*v-n,'\it\bfv','color',0.5*[1 1 1],'Rotation',atan2(v(2),v(1))/deg,'HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot,[A-h*v A+(b+h)*v],'k','linewidth',2.0);
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','bottom')
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','StreckeStrahlGerade-3')

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',42,varargin{:});


function Spitze(P,v,L,phi,varargin);
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)],varargin{:},'EdgeColor','none')
end
