function HyperbolWalzen

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

close all
deg=pi/180;
d=2;          % halber Abstand zwischen den Achsen
alpha=60*deg; % halber Winkel zwischen den Achsrichtungen
A=[d;0;0];
v=12*[0;cos(alpha);sin(alpha)];
[X,Y,Z,Lambda,Xg,Yg,Zg]=calcHyp(A-v,A+v);
aRg=30*[-1 1];
plot3([0 0],[0 0],aRg,'-.k','linewidth',2.0)
hold('on')
plot3(2*[d d],-sin(2*alpha)*aRg,cos(2*alpha)*aRg,'-.k','linewidth',2.0)
plotHyp(X,Y,Z,Lambda,Xg,Yg,Zg)
plot3(X(:,1),Y(:,1),Z(:,1),'k','linewidth',4.0)
X2=X+2*d;
Y2=cos(2*alpha)*Y-sin(2*alpha)*Z;
Z2=sin(2*alpha)*Y+cos(2*alpha)*Z;
X2g=Xg+2*d;
Y2g=cos(2*alpha)*Yg-sin(2*alpha)*Zg;
Z2g=sin(2*alpha)*Yg+cos(2*alpha)*Zg;
plotHyp(X2,Y2,Z2,Lambda,X2g,Y2g,Z2g)
hold('off')
axis('equal')
view(23,20);
axis([-3 5 -10 22 -10 7])
axis('off')
print('-deps','HyperbolWalzen','-opengl');

function [X,Y,Z,Lambda,Xg,Yg,Zg]=calcHyp(P0,P1)
deg=pi/180;
v=P1-P0;
lambda=[0:360]*deg;
t=[0 1];
[Lambda,T]=meshgrid(lambda,t);
X=(P0(1)+T*v(1)).*cos(Lambda)-(P0(2)+T*v(2)).*sin(Lambda);
Y=(P0(1)+T*v(1)).*sin(Lambda)+(P0(2)+T*v(2)).*cos(Lambda);
Z=(P0(3)+T*v(3));
lambda=[0:15:360]*deg;
[LambdaG,T]=meshgrid(lambda,t);
Xg=(P0(1)+T*v(1)).*cos(LambdaG)-(P0(2)+T*v(2)).*sin(LambdaG);
Yg=(P0(1)+T*v(1)).*sin(LambdaG)+(P0(2)+T*v(2)).*cos(LambdaG);
Zg=(P0(3)+T*v(3));

function plotHyp(X,Y,Z,Lambda,Xg,Yg,Zg)
surf(X,Y,Z,Lambda)
c=0.5+0.375*(cos(pi*[0:size(Lambda,2)-1]/(size(Lambda,2)-1))).^2;
colormap(repmat(c',1,3));
shading('interp')
plot3(Xg,Yg,Zg,'k')

