function RotationFktVerallg

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

deg=pi/180;
syms('t','u','v','real');
clc;
close('all')
c1=(2+0.5*sin(u))*cos(v);
c2=(3+0.3*sin(v*u))*sin(v);
xInl=inline('u','u','v');
yInl=inline(vectorize(c1),'u','v');
zInl=inline(vectorize(c2),'u','v');
u=(180+[0:20:720])*deg;
v=[0:1:360]*deg;
[U,V]=meshgrid(u,v);
X=xInl(U,V);
Y=yInl(U,V);
Z=zInl(U,V);
surf(X,Y,Z,V,'EdgeColor','none');
c=0.5+0.375*(cos(pi*[0:size(V,1)-1]/(size(V,1)-1))).^2;
colormap(repmat(c',1,3));
hold('on')
xRef=u(1)+1.75*pi;
plot3(X,Y,Z,'color',0.95*[1 1 1],'linewidth',2.0)
for xx=[u(1) xRef u(end)]
  plot3(repmat(xx,size(v)),yInl(xx,v),zInl(xx,v),'k','linewidth',2.0)
  fill3(repmat(xx,size(v)),yInl(xx,v),zInl(xx,v),mean(c)*[1 1 1])
end
vRef=v(round(0.75*end));
Schrift([u(1);yInl(u(1),vRef);zInl(u(1),vRef)],{'Schnitt-' 'fläche {\itS}({\ita})'},...
  'HorizontalAlignment','right','VerticalAlignment','top','erase','none')
Schrift([xRef;yInl(xRef,vRef);zInl(xRef,vRef)],{'  ^{    }Schnitt-' 'fläche {\itS}({\itx})'},...
  'HorizontalAlignment','left','VerticalAlignment','top','erase','none')
Schrift([u(end);yInl(u(end),vRef);zInl(u(end),vRef)],{'  ^{   }Schnitt-' 'fläche {\itS}({\itb})'},...
  'HorizontalAlignment','left','VerticalAlignment','top','erase','none')
xRg=[min(X(:));max(X(:))]+(max(X(:))-min(X(:)))*[-0.2;0.2];
yRg=[min(Y(:));max(Y(:))]+(max(Y(:))-min(Y(:)))*[-0.0;0.0];
plot3(xRg,[0;0],[0;0],'k','linewidth',2.0)
Spitze([xRg(2);0;0],[1;0;0],0.75,30*deg);
Schrift([xRg(2);0;0],'\itx','HorizontalAlignment','left','VerticalAlignment','middle','erase','none')
axis('equal')
axis([xRg' yRg' 0.5*min(Z(:)) 0.5*max(Z(:))])
axis('off')
view(-24,42)
print('-depsc','RotationFktVerallg','-opengl')

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

function Spitze(P,v,L,phi);
deg=pi/180;
if nargin<=2
  L=1;
end
if nargin<=3
  phi=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(phi/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');
    end
  end
