function Zykloide

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

close all
global ax 
ax=[inf -inf inf -inf];
r=1;
a=[0.6 1 1.4]*r;
h=0.4;
deg=pi/180;
phi=[0:360]*deg;
t=[0:360]*deg;
hold('on')
drawPolygon(@fill,[a(end)*cos(phi);r+a(end)*sin(phi)],0.875*[1 1 1],'edgecolor',0.875*[1 1 1])
drawPolygon(@fill,[r*cos(phi);r+r*sin(phi)],0.75*[1 1 1],'edgecolor',0.75*[1 1 1])
t=[-200:1000]*deg;
typ={'--k' 'k' '-.k'};
hdl=zeros(3,1);
drawPolygon(@plot,[r*t-a(1)*sin(t);r-a(1)*cos(t)],'color',0*[1 1 1],'linewidth',0.5)
drawPolygon(@plot,[r*t-a(end)*sin(t);r-a(end)*cos(t)],'color',0.*[1 1 1],'linewidth',0.5)
drawPolygon(@plot,[r*t-a(1)*sin(t);r-a(1)*cos(t)],'color',0.75*[1 1 1],'linewidth',0.5)
drawPolygon(@plot,[r*t-a(end)*sin(t);r-a(end)*cos(t)],'color',0.875*[1 1 1],'linewidth',0.5)
for k=1:length(a)
  P=[r*t-a(k)*sin(t);r-a(k)*cos(t)];
  hdl(k)=drawPolygon(@plot,P,typ{k},'linewidth',2.0);
end
ax=[[-1.1 9]*a(end) r+[-1 1]*a(end)]+[-1 2 -0.5 1.5]*h;
u=[-a a];
[xG,yG]=meshgrid([ax(1) unique([u [2 4]*pi*r]) ax(2)],[ax(3) unique([0 u])+r ax(4)]);
plot(xG,yG,xG',yG','color',0.5*[1 1 1]);
Schrift([-a(3)-0.1*h;ax(3)],'-{\ita}_{3 }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','baseline')
Schrift([-a(2);ax(3)],'-{\itr}_{  }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([-a(1);ax(3)],'-{\ita}_{1 }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([0.2*h;ax(3)],'0_{  }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ a(1)-0.2*h;ax(3)],'{\ita}_{1 }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','baseline')
Schrift([ a(2)+0.1*h;ax(3)],'{\itr}_{ }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ a(3);ax(3)],'{\ita}_{3 }','rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
for k=[2 4]
  Schrift([k*pi*r;ax(3)],[int2str(k) '\pi{\it r}_{  }'],'rotation',90,'HorizontalAlignment','right','VerticalAlignment','middle')
end
Schrift([ax(1);r-a(3)],'{\itr}-{\ita}_{3 }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);r-a(1)+0.1*h],'{\itr}-{\ita}_{1 }','HorizontalAlignment','right','VerticalAlignment','baseline')
Schrift([ax(1);-0.4*h ],'0_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);r     ],'{\itr}_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);r+a(1)],'{\itr}+{\ita}_{1 }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);2*r   ],'{\it2r}_{ }','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift([ax(1);r+a(3)+0.5*h],'{\itr}+{\ita}_{3 }','HorizontalAlignment','right','VerticalAlignment','baseline')

plot(ax(1:2),[0 0],'k')
plot([0 0],ax(3:4),'k')
Spitze([ax(2);0],[1;0],h,30*deg,'k');
Spitze([0;ax(4)],[0;1],h,30*deg,'k');
Schrift([ax(2);0.2*h],'\itx','HorizontalAlignment','right','VerticalAlignment','top','erase','none')
Schrift([0.3*h;ax(4)+0.6*h],'\ity','HorizontalAlignment','left','VerticalAlignment','top','erase','none')
axis('equal')
axis(ax)
axis('off')
hold('off')
set(legend(hdl,'{\ita}={\ita}_1<{\itr}','{\ita}={\ita}_2={\itr}','{\ita}={\ita}_3>{\itr}',4),...
  'position',[0.6288 0.3473 0.1571 0.1600],'FontName','TimesNewRoman','FontSize',12);

print('-depsc','Zykloide');

function h=drawPolygon(draw,P,varargin);
global ax
p=feval(draw,P(1,:),P(2,:),varargin{:});
if nargout
  h=p;
end
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',12,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
