function Gluehlampe

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

global AbbNr
AbbNr=0;
close('all')
clc
deg=pi/180;

hold('on')
Abb( 1*deg, 1*deg,@AbbKont)
Abb( 9*deg, 9*deg,@AbbTriang)
Abb(18*deg,18*deg,@AbbTriang)
Abb(36*deg,36*deg,@AbbTriang)
Abb(45*deg,45*deg,@AbbTriang)
Abb(60*deg,60*deg,@AbbTriang)
hold('off')
axis('equal')
view(0,15);
zlim([-19 15])
axis('off')
print('-deps','Gluehlampe','-opengl');

function AbbKont(Ti,Phi,X,Y,Z)
surfl(X,Y,Z);
colormap('gray');
shading('interp');

function AbbTriang(Ti,Phi,X,Y,Z)
trimesh(delaunay(Ti,Phi),X,Y,Z,'EdgeColor','black');

function Abb(dt,dphi,fcnProj)
global AbbNr offset xRg
AbbNr=AbbNr+1;
deg=pi/180;
alpha=acos(11.5/31)/deg;
beta=2*asin(10/23)/deg;
t=[-alpha -beta  0 90  180 180+beta 180+alpha]*deg;
r=[    31    23 23 27   23       23        31];
ti=linspace(t(1),t(end),round((t(end)-t(1))/dt));
ri=spline(t,[dr_dt(t(1),r(1),[0;1]) r dr_dt(t(end),r(end),[0;1])],ti);
[xPr,zPr]=pol2cart(ti,ri);
phi=0:dphi:pi;
co=cos(phi);
si=sin(phi);
[Ti  Phi]=meshgrid(ti, phi);
[XPr Phi]=meshgrid(xPr,phi);
[Z   Phi]=meshgrid(zPr,phi);
X=cos(Phi).*XPr;
Y=sin(Phi).*XPr;
if AbbNr==1
  offset=-1.2*(max(max(X))-min(min(X)));
  ylim([min(min(Y)) max(max(Y))])
  zlim([min(min(Z)) max(max(Z))])
  xRg=[min(min(X)) max(max(X))];
end
X=X+offset*(AbbNr-1);
xRg=[min(xRg(1),min(min(X))) max(xRg(2),max(max(X)))];
xlim(xRg)
feval(fcnProj,Ti,Phi,X,Y,Z);

function dr=dr_dt(t,r,T);
v1=[cos(t);sin(t)];
v2=[-v1(2);v1(1)];
dr=r*(T'*v1)/(T'*v2);
