function KreisEllipse

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

global ax
close('all')
deg=pi/180;
A=[0;0];
r=1;
h=0.1;
a=1.5;
b=1.2;
t0=20*deg;
t1=240*deg;
r0=0.5*r;
r1=r;
ax=[-a-h/10 a+3*h -b-h/10 b+2.5*h];

figure('numbertitle','off','name','Kreis');
drawPolygon(@plot,A,'o','color',0.5*[1 1 1],'Markersize',10);
Schrift(A,'{\itP}_{0 }','color',0.5*[1 1 1],'HorizontalAlignment','right','VerticalAlignment','bottom')
hold('on')
t=[0:360]*deg;
drawPolygon(@plot,[A A+r*[cos(t1);sin(t1)]],'color',0.5*[1 1 1])
Schrift(A+0.5*r*[cos(t1);sin(t1)],'\itr','color',0.5*[1 1 1],'Rotation',180+t1/deg,...
    'HorizontalAlignment','center','VerticalAlignment','bottom')
drawPolygon(@plot,repmat(A,1,length(t))+r*[cos(t);sin(t)],'k','linewidth',2.0)
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','-loose','KreisEllipse-1')

figure('numbertitle','off','name','Kreisbogen');
drawPolygon(@plot,A+r*[1;0],'.','Markersize',30,'color',0.5*[1 1 1]);
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','bottom','color',0.5*[1 1 1])
hold('on')
for ti=[0 t0 t1]
    drawPolygon(@plot,[A A+r*[cos(ti);sin(ti)]],'color',0.5*[1 1 1]);
end
t=t0:deg:t1;
drawPolygon(@plot,repmat(A,1,length(t))+r*[cos(t);sin(t)],'k','linewidth',2.0)
drawPolygon(@plot,[A+r*[cos(t0);sin(t0)] A+r*[cos(t1);sin(t1)]],'.k','Markersize',30);
Schrift(A+r*[1;0],'{ }{\itt}=0','HorizontalAlignment','left','VerticalAlignment','middle','color',0.5*[1 1 1])
Schrift(A+r*[cos(t(1));sin(t(1))],'_{ }{\itt}={\itt}_0','Rotation',t0/deg,...
    'HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(A+r*[cos(t(end));sin(t(end))],'{\itt}={\itt}_{1 }','Rotation',180+t1/deg,...
    'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(A+0.5*r*[cos(t1);sin(t1)],'\itr','Rotation',180+t1/deg,...
    'HorizontalAlignment','center','VerticalAlignment','bottom','color',0.5*[1 1 1])
t=[t(end):deg:360*deg+t(1)];
drawPolygon(@plot,repmat(A,1,length(t))+r*[cos(t);sin(t)],'color',0.5*[1 1 1])
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','-loose','KreisEllipse-2')

figure('numbertitle','off','name','Ellipse');
drawPolygon(@plot,A,'ok','Markersize',10);
Schrift(A,'{\itO}','HorizontalAlignment','right','VerticalAlignment','top')
hold('on')
t=[0:360]*deg;
drawPolygon(@plot,repmat(A,1,length(t))+diag([a,b])*[cos(t);sin(t)],'k','linewidth',2.0)
u=0.8;
drawPolygon(@plot,[A-[0;h/2] A+[u;-h/2]],'color',0.5*[1 1 1],'linewidth',2.0)
drawPolygon(@plot,[A-[h/2;0] A+[-h/2;u]],'color',0.5*[1 1 1],'linewidth',2.0)
drawPolygon(@plot,repmat(A,1,length(t))+u*[cos(t);sin(t)],'color',0.5*[1 1 1],'linewidth',2.0)
drawPolygon(@plot,[A A+[a;0]],'color',0.0*[1 1 1],'linewidth',2.0)
drawPolygon(@plot,[A A+[0;b]],'color',0.0*[1 1 1],'linewidth',2.0)
Spitze([u;-h/2],[1;0],h,90*deg,0.5*[1 1 1]);
Spitze([-h/2;u],[0;1],h,90*deg,0.5*[1 1 1]);
Spitze([a;0],[1;0],h,90*deg,0.0*[1 1 1]);
Spitze([0;b],[0;1],h,90*deg,0.0*[1 1 1]);
Schrift([u-0.9*h;-h/2],'{\bf\ite}_1','color',0.5*[1 1 1],'HorizontalAlignment','center','VerticalAlignment','top');
Schrift([-h/2;u-h/2],'{\bf\ite}_{2  }','color',0.5*[1 1 1],'HorizontalAlignment','right','VerticalAlignment','middle');
Schrift([a+2*h;0],'{\bf\ite}_1''={\ita\bfe}_1','color',0.0*[1 1 1],'HorizontalAlignment','center','VerticalAlignment','bottom');
Schrift([0;b-2*h],'{\bf\ite}_2''={\itb\bfe}_2','color',0.0*[1 1 1],'HorizontalAlignment','left','VerticalAlignment','bottom');
hold('off')
axis('off')
axis('equal');
axis(ax);
print('-depsc','-loose','KreisEllipse-3')

figure('numbertitle','off','name','Kreisringsektor');
Schrift(A,'{\itP}_0','HorizontalAlignment','center','VerticalAlignment','baseline','erase','xor')
hold('on')
for ti=[t0 t1]
  drawPolygon(@plot,[A A+r*[cos(ti);sin(ti)]],'k');
end
t=t0:deg:t1;
K0=repmat(A,1,length(t))+r0*[cos(t);sin(t)];
K1=repmat(A,1,length(t))+r1*[cos(t);sin(t)];
drawPolygon(@fill,[K0 K1(:,end:-1:1)],0.875*[1 1 1],'edgecolor','none')
drawPolygon(@plot,[A+r0*[cos(t0);sin(t0)] A+r0*[cos(t1);sin(t1)]],'.k','Markersize',30);
drawPolygon(@plot,[A+r1*[cos(t0);sin(t0)] A+r1*[cos(t1);sin(t1)]],'.k','Markersize',30);
Schrift(A+r1*[cos(t(1));sin(t(1))],'_{  }{\itt}={\itt}_0','Rotation',t0/deg,...
    'HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(A+r1*[cos(t(end));sin(t(end))],'{\itt}={\itt}_{1 }','Rotation',180+t1/deg,...
    'HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(A+r1*[cos(t0);sin(t0)],'_{ }{\itr}={\itr}_1','Rotation',t0/deg-90,...
    'HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(A+r0*[cos(t0);sin(t0)],'_{ }{\itr}={\itr}_0','Rotation',t0/deg-90,...
    'HorizontalAlignment','left','VerticalAlignment','middle')
hold('off')
axis('off')
axis('equal');
ax=r1*[-1 1 -1.1 1];
axis(ax);
print('-depsc','-loose','KreisEllipse-4')

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