function Hesse3d

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

global ax
ax=[inf -inf inf -inf inf -inf];
close('all')
deg=pi/180;
A=[0;0;0];
a=-0.7;
b=1.7;
c=-0.6;
d=1.6;
h=0.2;
v=[4;-5;0];
v=v/norm(v);
w=[11;4;2];
w=1.5*w/norm(w);
n=cross(v,w);
K=null(n');
Proj=K*K';

figure('numbertitle','off','name','null');
drawPolygon(@plot3,A,'.k','Markersize',30,'erase','xor');
hold('on')
P=A+1.3*v+1.2*w+0.0*n;
drawPolygon(@fill3,[A+a*v+c*w A+b*v+c*w A+b*v+d*w A+a*v+d*w A+a*v+c*w],0.875*[1 1 1],'edgecolor','none');
drawPolygon(@plot3,[A+w A A+v],'k','erase','xor');
drawPolygon(@plot3,[A A+n],'k','erase','xor');
Schrift(A+0.5*(a+b)*v+c*w,'\Pi','HorizontalAlignment','right','VerticalAlignment','top','erase','xor')
Spitze(A+v,v,h,30*deg,'erase','xor');
Schrift(A+v,'\it\bfv','HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','middle','erase','xor')
Spitze(A+w,w,h,30*deg,'erase','xor');
Schrift(A+w,'\it\bfw','HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Spitze(A+n,n,h,30*deg,'erase','xor');
Schrift(A+1.1*n,'\it\bfn_{ }','HorizontalAlignment','right','VerticalAlignment','top','erase','xor');
drawPolygon(@plot3,[A P],'k','erase','xor');
Spitze(P,P-A,h,30*deg,'erase','xor');
Schrift(P,'\itP','HorizontalAlignment','left','VerticalAlignment','baseline','erase','xor')
Schrift(0.2*A+0.8*P+0.03*n,'{\itP}-{\itP}_0','FontSize',27,'HorizontalAlignment','right','VerticalAlignment','top','erase','xor')
alpha=acos((P-A)'*n/(norm(P-A)*norm(n)));
e1=n/norm(n);
e3=cross(P-A,n);
e3=e3/norm(e3);
e2=cross(e1,e3);
e2=e2/norm(e2);
r=4*h;
t=degGrid(0,alpha);
plot3(A(1)+r*(cos(t)*e1(1)+sin(t)*e2(1)),...
      A(2)+r*(cos(t)*e1(2)+sin(t)*e2(2)),...
      A(3)+r*(cos(t)*e1(3)+sin(t)*e2(3)),'k','erase','xor');
hold('off')
axis('off')
axis('equal');
view(3,38)
axis([-1.3 3.4 -1.7 1.4 0 0.6])
print('-deps','Hesse3d-1')

figure('numbertitle','off','name','positiv');
drawPolygon(@plot3,A,'.k','Markersize',30,'erase','xor');
hold('on')
P=A+1.3*v+1.2*w+1.3*n;
Pg=A+Proj*(P-A);
drawPolygon(@fill3,[A+a*v+c*w A+b*v+c*w A+b*v+d*w A+a*v+d*w A+a*v+c*w],0.875*[1 1 1],'edgecolor','none');
drawPolygon(@plot3,[A+w A A+v],'k','erase','xor');
drawPolygon(@plot3,[A A+n],'k','erase','xor');
Schrift(A+0.5*(a+b)*v+c*w,'\Pi','HorizontalAlignment','right','VerticalAlignment','top','erase','xor')
Spitze(A+v,v,h,30*deg,'erase','xor');
Schrift(A+v,'\it\bfv','HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','middle','erase','xor')
Spitze(A+w,w,h,30*deg,'erase','xor');
Schrift(A+w,'\it\bfw','HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Spitze(A+n,n,h,30*deg,'erase','xor');
Schrift(A+1.1*n,'\it\bfn_{ }','HorizontalAlignment','right','VerticalAlignment','top','erase','xor');
drawPolygon(@plot3,[A P Pg],'k','erase','xor');
drawPolygon(@plot3,Pg,'ok','Markersize',10,'erase','xor');
Spitze(P,P-A,h,30*deg,'erase','xor');
Schrift(P,'\itP','HorizontalAlignment','left','VerticalAlignment','baseline','erase','xor')
Schrift((A+P)/2-0.05*n,'{\itP}-{\itP}_0','FontSize',27,'HorizontalAlignment','right','VerticalAlignment','bottom','erase','xor')
Schrift((Pg+P)/2,'{\itProj_{\bfn}}({\itP}-{\itP}_0)','FontSize',27,'HorizontalAlignment','left','VerticalAlignment','middle','erase','xor')
Spitze(P,n,h,30*deg,'erase','xor');
Schrift(Pg,'{\itP}_{\Pi }','HorizontalAlignment','right','VerticalAlignment','baseline','erase','xor')
alpha=acos((P-A)'*n/(norm(P-A)*norm(n)));
e1=n/norm(n);
e3=cross(P-A,n);
e3=e3/norm(e3);
e2=cross(e1,e3);
e2=e2/norm(e2);
r=4*h;
t=degGrid(0,alpha);
plot3(A(1)+r*(cos(t)*e1(1)+sin(t)*e2(1)),...
      A(2)+r*(cos(t)*e1(2)+sin(t)*e2(2)),...
      A(3)+r*(cos(t)*e1(3)+sin(t)*e2(3)),'k','erase','xor');
hold('off')
axis('off')
axis('equal');
view(3,38)
axis([-1.3 3.4 -1.7 1.4 0 0.6])
print('-deps','Hesse3d-2')

figure('numbertitle','off','name','negativ');
drawPolygon(@plot3,A,'.k','Markersize',30,'erase','xor');
hold('on')
P=A+1.3*v+1.2*w-1.3*n;
Pg=A+Proj*(P-A);
drawPolygon(@fill3,[A+a*v+c*w A+b*v+c*w A+b*v+d*w A+a*v+d*w A+a*v+c*w],0.875*[1 1 1],'edgecolor','none');
drawPolygon(@plot3,[A+w A A+v],'k','erase','xor');
drawPolygon(@plot3,[A A+n],'k','erase','xor');
Schrift(A+0.5*(a+b)*v+c*w,'\Pi','HorizontalAlignment','right','VerticalAlignment','top','erase','xor')
Spitze(A+v,v,h,30*deg,'erase','xor');
Schrift(A+v,'\it\bfv  ','HorizontalAlignment','right','VerticalAlignment','baseline','erase','xor');
Schrift(A,'{\itP}_{0 }','HorizontalAlignment','right','VerticalAlignment','middle','erase','xor')
Spitze(A+w,w,h,30*deg,'erase','xor');
Schrift(A+w,'\it\bfw','HorizontalAlignment','left','VerticalAlignment','middle','erase','xor');
Spitze(A+n,n,h,30*deg,'erase','xor');
Schrift(A+1.1*n,'\it\bfn_{ }','HorizontalAlignment','right','VerticalAlignment','top','erase','xor');
drawPolygon(@plot3,[A P Pg],'k','erase','xor');
drawPolygon(@plot3,Pg,'ok','Markersize',10,'erase','xor');
Spitze(P,P-A,h,30*deg,'erase','xor');
Schrift(P,'^{ }\itP','HorizontalAlignment','left','VerticalAlignment','baseline','erase','xor')
Schrift((A+P)/2,'{\itP}-{\itP}_0','FontSize',27,'HorizontalAlignment','right','VerticalAlignment','top','erase','xor')
Schrift((Pg+P)/2,'{\itProj_{\bfn}}({\itP}-{\itP}_0)','FontSize',27,'HorizontalAlignment','left','VerticalAlignment','middle','erase','xor')
Spitze(P,-n,h,30*deg,'erase','xor');
Schrift(Pg,'{\itP}_{\Pi }','HorizontalAlignment','right','VerticalAlignment','baseline','erase','xor')
alpha=acos((P-A)'*n/(norm(P-A)*norm(n)));
e1=n/norm(n);
e3=cross(P-A,n);
e3=e3/norm(e3);
e2=cross(e1,e3);
e2=e2/norm(e2);
r=4*h;
t=degGrid(0,alpha);
plot3(A(1)+r*(cos(t)*e1(1)+sin(t)*e2(1)),...
      A(2)+r*(cos(t)*e1(2)+sin(t)*e2(2)),...
      A(3)+r*(cos(t)*e1(3)+sin(t)*e2(3)),'k','erase','xor');
hold('off')
axis('off')
axis('equal');
view(3,38)
axis([-1.3 3.4 -1.7 1.4 -0.6 0.3])
print('-deps','Hesse3d-3')

function drawPolygon(draw,P,varargin);
global ax
feval(draw,P(1,:),P(2,:),P(3,:),varargin{:})
if min(P(1,:))<ax(1)
  ax(1)=min(P(1,:));
end
if max(P(1,:))>ax(2)
  ax(2)=max(P(1,:));
end
if min(P(2,:))<ax(3)
  ax(3)=min(P(2,:));
end
if max(P(2,:))>ax(4)
  ax(4)=max(P(2,:));
end
if min(P(3,:))<ax(5)
  ax(5)=min(P(3,:));
end
if max(P(3,:))>ax(6)
  ax(6)=max(P(3,:));
end

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

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

function t=degGrid(t1,t2,d);
if nargin<3
  d=1;
end
deg=pi/180;
delta=d*deg;
t=linspace(t1,t2,round((t2-t1)/delta));