function KoordinatenflZyl

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

clc;
close('all')
deg=pi/180;
h=0.3;

global ax
ax=[-1 1 -1 1 0 1];
lam=40*deg;
rho=0.8;
P=[rho*[cos(lam);sin(lam)];0.9];
O=[0;0;0];

figure('numbertitle','off','name','lambda=const');
[U1,U2]=meshgrid(linspace(-h,ax(6)+h,100),linspace(0,rho+h,100));
V1=[0;0;1];
V2=[cos(lam);sin(lam);0];
X=U1*V1(1)+U2*V2(1);
Y=U1*V1(2)+U2*V2(2);
Z=U1*V1(3)+U2*V2(3);
surf(X,Y,Z,U2)
c=0.5+0.375*(cos(pi/2*[0:size(X,1)-1]/(size(X,1)-1))).^2;
colormap(repmat(c',1,3));
shading('interp')
hold('on')
drawPolygon(@plot3,[O [P(1:2);0] P],'k','erase','none','linewidth',1.5)
Schrift(0.5*rho*[cos(lam);sin(lam);0],'   \it\rho',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
Spitze([P(1:2);0],[P(1:2);0],h/3,30*deg);
Schrift([rho*[cos(lam);sin(lam)];P(3)/2],' \ith',...
  'HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Spitze(P,[0;0;1],h/3,30*deg);
drawPolygon(@plot3,[O [ax(2)+h;0;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;ax(4)+h;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;0;ax(6)+h]],'k','erase','none','linewidth',1.5);
Spitze([ax(2)+h/3;0;0],[1;0;0],h/3,45*deg);
Spitze([0;ax(4)+h/3;0],[0;1;0],h/3,45*deg);
Spitze([0;0;ax(6)+h/3],[0;0;1],h/3,45*deg);
Schrift([ax(2)+h/3;0;0],'\itx','HorizontalAlignment','right','VerticalAlignment','top');
Schrift([0;ax(4)+h/3;0],'\ity','HorizontalAlignment','left','VerticalAlignment','middle');
Schrift([0;0;ax(6)+2/3*h],'\itz ','HorizontalAlignment','right','VerticalAlignment','top');
[xK,yK]=pol2cart(degGrid(0,lam),rho/2);
drawPolygon(@plot3,[xK;yK;zeros(size(xK))],'k','erase','none','linewidth',1.5);
Schrift(rho/2*[cos(lam/2);sin(lam/2);0],'\it\lambda',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
hold('off')
axis('off')
axis('equal')
view(99,22)
print('-deps','KoordinatenflZyl-lam','-opengl');

figure('numbertitle','off','name','rho=const');
[Lam,H]=meshgrid([-180:180]*deg,linspace(-h,ax(6)+h,100));
[X,Y,Z]=pol2cart(Lam,rho,H);
surf(X,Y,Z,Lam)
c=0.5+0.375*(sin(pi*[0:size(X,1)-1]/(size(X,1)-1))).^2;
colormap(repmat(c',1,3));
shading('interp')
hold('on')
[xK,yK]=pol2cart([-180:180]*deg,rho);
drawPolygon(@plot3,[xK;yK;zeros(size(xK))],'k','erase','none')
drawPolygon(@plot3,[O [P(1:2);0] P],'k','erase','none','linewidth',1.5)
Schrift(0.5*rho*[cos(lam);sin(lam);0],'   \it\rho',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
Schrift([rho*[cos(lam);sin(lam)];P(3)/2],' \ith',...
  'HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Spitze(P,[0;0;1],h/3,30*deg);
drawPolygon(@plot3,[O [ax(2)+h;0;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;ax(4)+h;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;0;ax(6)+h]],'k','erase','none','linewidth',1.5);
Spitze([ax(2)+h/3;0;0],[1;0;0],h/3,45*deg);
Spitze([0;ax(4)+h/3;0],[0;1;0],h/3,45*deg);
Spitze([0;0;ax(6)+h/3],[0;0;1],h/3,45*deg);
Schrift([ax(2)+h/3;0;0],'\itx','HorizontalAlignment','right','VerticalAlignment','top');
Schrift([0;ax(4)+h/3;0],'\ity','HorizontalAlignment','left','VerticalAlignment','middle');
Schrift([0;0;ax(6)+h/3],'\itz','HorizontalAlignment','center','VerticalAlignment','bottom');
[xK,yK]=pol2cart(degGrid(0,lam),rho/2);
drawPolygon(@plot3,[xK;yK;zeros(size(xK))],'k','erase','none','linewidth',1.5);
Schrift(rho/2*[cos(lam/2);sin(lam/2);0],'\it\lambda',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
Spitze([xK(end);yK(end);0],[-yK(end);xK(end);0],h/3,30*deg);
hold('off')
axis('off')
axis('equal')
view(99,22)
print('-deps','KoordinatenflZyl-rho','-opengl');

figure('numbertitle','off','name','h=const');
[U1,U2]=meshgrid(linspace(ax(1),ax(2),100),linspace(ax(3),ax(4),100));
V1=[1;0;0];
V2=[0;1;0];
X=     U1*V1(1)+U2*V2(1);
Y=     U1*V1(2)+U2*V2(2);
Z=P(3)+U1*V1(3)+U2*V2(3);
surf(X,Y,Z,U1)
c=0.5+0.375*(sin(pi/2*[0:size(X,1)-1]/(size(X,1)-1))).^2;
colormap(repmat(c',1,3));
shading('interp')
hold('on')
drawPolygon(@plot3,[O [P(1:2);0] P],'k','erase','none','linewidth',1.5)
Schrift(0.5*rho*[cos(lam);sin(lam);0],'   \it\rho',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
Spitze([P(1:2);0],[P(1:2);0],h/3,30*deg);
Schrift([rho*[cos(lam);sin(lam)];P(3)/2],' \ith',...
  'HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
drawPolygon(@plot3,[O [ax(2)+h;0;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;ax(4)+h;0]],'k','erase','none','linewidth',1.5);
drawPolygon(@plot3,[O [0;0;ax(6)+h]],'k','erase','none','linewidth',1.5);
Spitze([ax(2)+h/3;0;0],[1;0;0],h/3,45*deg);
Spitze([0;ax(4)+h/3;0],[0;1;0],h/3,45*deg);
Spitze([0;0;ax(6)+h/3],[0;0;1],h/3,45*deg);
Schrift([ax(2)+h/3;0;0],'\itx','HorizontalAlignment','right','VerticalAlignment','top');
Schrift([0;ax(4)+h/3;0],'\ity','HorizontalAlignment','left','VerticalAlignment','middle');
Schrift([0;0;ax(6)+h/3],'\itz','HorizontalAlignment','center','VerticalAlignment','bottom');
[xK,yK]=pol2cart(degGrid(0,lam),rho/2);
drawPolygon(@plot3,[xK;yK;zeros(size(xK))],'k','erase','none','linewidth',1.5);
Schrift(rho/2*[cos(lam/2);sin(lam/2);0],'\it\lambda',...
  'HorizontalAlignment','center','VerticalAlignment','top','erase','xor');
Spitze([xK(end);yK(end);0],[-yK(end);xK(end);0],h/3,30*deg);
hold('off')
axis('off')
axis('equal')
view(99,22)
print('-deps','KoordinatenflZyl-h','-opengl');

function drawPolygon(draw,P,varargin);
global ax
feval(draw,P(1,:),P(2,:),P(3,:),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
if min(P(3,:))<ax(5)
  ax(5)=min(P(3,:));
end
if max(P(3,:))>ax(6)
  ax(6)=max(P(3,:));
end

function Schrift(P,txt,varargin)
text(P(1),P(2),P(3),txt,'FontName','TimesNewRoman','FontSize',24,varargin{:});

function Spitze(P,v,L,lambda,varargin);
deg=pi/180;
if nargin<=2
  L=1;
end
if nargin<=3
  lambda=7.5*deg;
end
v=L*v./repmat(sqrt(dot(v,v)),size(P,1),1);
Q=P-v;
t=[0:6:360]*deg;
for k=1:size(P,2)
  N=tan(lambda/2)*null(v(:,k)');
  for w=2:length(t)
    plot3(...
      [P(1,k) Q(1,k)+cos(t(w))*L(:,k)*N(1,1)+sin(t(w))*L(:,k)*N(1,2) Q(1,k)+cos(t(w-1))*L(:,k)*N(1,1)+sin(t(w-1))*L(:,k)*N(1,2) P(1,k)],...
      [P(2,k) Q(2,k)+cos(t(w))*L(:,k)*N(2,1)+sin(t(w))*L(:,k)*N(2,2) Q(2,k)+cos(t(w-1))*L(:,k)*N(2,1)+sin(t(w-1))*L(:,k)*N(2,2) P(2,k)],...
      [P(3,k) Q(3,k)+cos(t(w))*L(:,k)*N(3,1)+sin(t(w))*L(:,k)*N(3,2) Q(3,k)+cos(t(w-1))*L(:,k)*N(3,1)+sin(t(w-1))*L(:,k)*N(3,2) P(3,k)],...
      'k','erase','none',varargin{:});
    end
  end

function t=degGrid(t1,t2,d);
if nargin<3
  d=1;
end
deg=pi/180;
delta=d*deg;
t=linspace(t1,t2,round((t2-t1)/delta));

