function RotationFkt

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

deg=pi/180;
syms('t','u','v','real');
clc;
close('all')
c=[t;3+sin(3*t)*cos(5*t)/(1+sin(exp(t))^2);0];
f=inline(char(eval(c(2))),'t');
Phi=RK(c,t,sym([1;0;0]),u,v);
xRKInl=inline(vectorize(Phi(1)),'u','v');
yRKInl=inline(vectorize(Phi(2)),'u','v');
zRKInl=inline(vectorize(Phi(3)),'u','v');
[xi,yi]=fplot(f,[pi 3*pi]);
[U,V]=meshgrid(xi,[0:10:360]*deg);
X=xRKInl(U,V);
Y=yRKInl(U,V);
Z=zRKInl(U,V);
surf(X,Y,Z,V);
c=0.5+0.375*(cos(pi*[0:size(V,1)-1]/(size(V,1)-1))).^2;
colormap(repmat(c',1,3));
hold('on')
uRef=round(size(U,1));
plot3(xi,yi,zeros(size(xi)),'k','linewidth',4.0)
Schrift([X(uRef,1);Y(uRef,1);Z(uRef,1)],'{\ity}={\itf}({\itx}) ','HorizontalAlignment','right','VerticalAlignment','bottom','erase','none')
plot3(X,Y,Z,'k')
xRg=[min(X(:));max(X(:))]+(max(X(:))-min(X(:)))*[-0.8;1.0];
yRg=[min(Y(:));max(Y(:))]+(max(Y(:))-min(Y(:)))*[-0.3;0.3];
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')
plot3([0;0],yRg,[0;0],'k','linewidth',2.0)
Spitze([0;yRg(2);0],[0;1;0],0.75,30*deg);
Schrift([0;yRg(2);0],'\ity_{  }','HorizontalAlignment','center','VerticalAlignment','middle','erase','none')
axis('equal')
view(-55,10)
axis([0 10 yRg' -2.5 3.2])
axis('off')
shading('interp')
print('-deps','RotationFkt')

function Phi=RK(c,t,q,u,v);
Phi=(cos(v)*sym(eye(3))+(1-cos(v))*q*q'-sin(v)*[0 q(3) -q(2);-q(3) 0 q(1);q(2) -q(1) 0])*subs(c,t,u);

function Schrift(P,txt,varargin)
text(P(1),P(2),P(3),txt,'FontName','TimesNewRoman','FontSize',32,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','erase','none');
    end
  end
