function Kettenlinie

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

close all
global ax 
ax=[inf -inf inf -inf];
a=0.1;
h=a/10;
deg=pi/180;
x=linspace(-1.95*a,2*a,100);
drawPolygon(@plot,[x;a*cosh(x/a)],'k');
ax(3)=-h;
hold('on')
x=linspace(0.4*x(1),0.6*x(end),100);
[xG,yG]=meshgrid([ax(1) x([1 end]) ax(2)],[ax(3) a ax(4)]);
plot(xG,yG,xG',yG','color',0.5*[1 1 1]);
drawPolygon(@plot,[x;a*cosh(x/a)],'k','linewidth',4.0);
plot(ax(1:2),[0 0],'k')
plot([0 0],ax(3:4),'k')
Schrift([0;ax(3)],'0','HorizontalAlignment','center','VerticalAlignment','top')
Schrift([x(1);ax(3)],'{\itt}_0','HorizontalAlignment','center','VerticalAlignment','top')
Schrift([x(end);ax(3)],'{\itt}_1','HorizontalAlignment','center','VerticalAlignment','top')
Schrift([ax(1);0],'0 ','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);a],'\ita ','HorizontalAlignment','right','VerticalAlignment','middle')
axis('equal')
ax=ax+[0 0 0 -17]*h;
axis(ax);
Schrift([ax(2);0.2*h],'\itx','HorizontalAlignment','right','VerticalAlignment','bottom','erase','none')
Schrift([0.3*h;ax(4)+2*h],'_{ }\ity','HorizontalAlignment','left','VerticalAlignment','top','erase','none')
Spitze([ax(2);0],[1;0],2*h,30*deg,'k');
Spitze([0;ax(4)],[0;1],2*h,30*deg,'k');
axis('off')
hold('off')
print('-depsc','Kettenlinie');

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)
if length(P)==2
  P=[P;0];
end
text(P(1),P(2),P(3),txt,'FontName','TimesNewRoman','FontSize',36,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{:})
end
