function GeradesKreiskonoid

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

clc;
close('all')
deg=pi/180;
syms('t','u','v','real');
n=[0;1;0];                     % Normalenvektor der Richtebene
h=6;
P=[0;0;h]; w=n;                % Leitgerade
r=5;
c=[r*cos(t);r*sin(t);0];       % Leitkreis
Phi=Kon(P,w,c,t,n,u,v);
xKonInl=inline(vectorize(Phi(1)),'u','v');
yKonInl=inline(vectorize(Phi(2)),'u','v');
zKonInl=inline(vectorize(Phi(3)),'u','v');
ti=[0:6:360]*deg;
[U,V]=meshgrid(ti,[0 0.5 1]);
X=xKonInl(U,V);
Y=yKonInl(U,V);
Z=zKonInl(U,V);
surf(X,Y,Z,U);
c=0.5+0.375*(sin(pi*[0:size(U,2)-1]/(size(U,2)-1))).^2;
colormap(repmat(c',1,3));
vRef=round(0.34*length(ti));
Schrift([X(1,vRef);Y(1,vRef);Z(1,vRef)],'\itG_{        }','HorizontalAlignment','right','VerticalAlignment','top','erase','none')
Schrift([X(2,vRef);Y(2,vRef);Z(2,vRef)],'\itM_{  }','HorizontalAlignment','right','VerticalAlignment','middle','erase','none')
Schrift([X(3,vRef);Y(3,vRef);Z(3,vRef)],'\itD_{ }','HorizontalAlignment','right','VerticalAlignment','bottom','erase','none')
hold('on')
plot3(X',Y',Z','k','linewidth',2.0)
plot3(X',Y',Z','k','linewidth',0.5,'erase','none')
plot3([-r r],[0 0],[0 0],'k','erase','none')
plot3([0 0],[-r r],[0 0],'k','erase','none')
plot3([-r r]/2,[0 0],[h h]/2,'k','erase','none')
plot3([0 0],[-r r],[h h]/2,'k','erase','none')
Schrift([-r/2;0;0],'\itr','HorizontalAlignment','center','VerticalAlignment','bottom','erase','none');
Schrift([0;r/2;0],'\itr^{ }','HorizontalAlignment','right','VerticalAlignment','middle','erase','none');
Schrift([-r/4;0;h/2],'{\itr}/2','HorizontalAlignment','center','VerticalAlignment','bottom','erase','none');
Schrift([0;r/2;h/2],'_{ }\itr','HorizontalAlignment','left','VerticalAlignment','middle','erase','none');
hold('off')
view(-13,22)
axis('equal')
axis('off')
print('-deps','GeradesKreiskonoid','-opengl');

function Phi=Kon(P,w,c,t,n,u,v)
k=subs(c,t,u);  
Phi=simple(k+v*(SchnittGerEb(P,w,k,n)-k));

function S=SchnittGerEb(A,v,B,n)
syms('t','real');
S=simple(A+solve((A+t*v-B)'*n,t)*v);

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