function EbeneParallelspat

% http://geometrie.hs-nb.de/MATLAB-Programme/EbeneParallelspat.m   Bearbeitungsstand: 25.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.5;
c=0.4;
d=1.6;
e=0.8;
f=1.3;
h=0.2;
v=[11;4;0];
v=v/norm(v);
w=[4;-5;0];
w=1.5*w/norm(w);
u=cross(v,w);
u=u-0.5*w;
u=u/norm(u);
u(3)=abs(u(3));

figure('numbertitle','off','name','Parallelogramm');
drawPolygon(@plot3,A,'ok','Markersize',10);
hold('on')

n=0.25*h*[-v(2);v(1);0];
drawPolygon(@plot3,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'k');
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg);
Schrift(A+0.5*a*v-1.5*n,'\it\bfv','HorizontalAlignment','left','VerticalAlignment','middle');
drawPolygon(@plot3,[A+a*v A+b*v],'.k','Markersize',30);
drawPolygon(@plot3,[A-h*v A+a*v],'k');
drawPolygon(@plot3,[A+a*v A+b*v],'k','linewidth',2.0);
drawPolygon(@plot3,[A+b*v A+(b+h)*v],'k');
Schrift(A,'{\itP}_{0}','HorizontalAlignment','right','VerticalAlignment','top')
Schrift(A+a*v,'{\itP}_0+{\ita\bfv}','HorizontalAlignment','right','VerticalAlignment','baseline')
Schrift(A+b*v,'{\itP}_0+{\itb\bfv}','HorizontalAlignment','right','VerticalAlignment','baseline')

n=0.25*h*[-w(2);w(1);0];
drawPolygon(@plot3,[A+0.5*h*w-n A+(c-0.5*h)*w-n],'k');
Spitze(A+(c-0.5*h)*w-n,w,0.25*h,45*deg);
Schrift(A+0.5*c*w+0.5*n,'\it\bfw','HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot3,[A+c*w A+d*w],'.k','Markersize',30);
drawPolygon(@plot3,[A-h*w A+c*w],'k');
drawPolygon(@plot3,[A+c*w A+d*w],'k','linewidth',2.0);
drawPolygon(@plot3,[A+d*w A+(d+h)*w],'k');
Schrift(A+c*w,'{\itP}_0+{\itc\bfw}_{ }','HorizontalAlignment','left','VerticalAlignment','top')
Schrift(A+d*w,'{\itP}_0+{\itd\bfw}_{ }','HorizontalAlignment','center','VerticalAlignment','top')

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.75*[1 1 1],'edgecolor','none');
hold('off')
view(2)
axis('off')
axis('equal');
ax=[0 2.5 -2 0 A(3)+0.1*h*[-1 1]];
axis(ax);
print('-depsc','EbeneParallelspat-1')

figure('numbertitle','off','name','Viertelebene');
drawPolygon(@plot3,A,'ok','Markersize',10);
hold('on')

n=0.25*h*[-v(2);v(1);0];
drawPolygon(@plot3,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'k');
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg);
Schrift(A+0.5*a*v-1.5*n,'\it\bfv','HorizontalAlignment','left','VerticalAlignment','middle');
drawPolygon(@plot3,A+a*v,'.k','Markersize',30);
drawPolygon(@plot3,[A-h*v A+a*v],'k');
drawPolygon(@plot3,[A+a*v A+(b+h)*v],'k','linewidth',2.0);
Schrift(A,'{\itP}_{0}','HorizontalAlignment','right','VerticalAlignment','top')
Schrift(A+a*v,'{\itP}_0+{\ita\bfv}','HorizontalAlignment','right','VerticalAlignment','baseline')

n=0.25*h*[-w(2);w(1);0];
drawPolygon(@plot3,[A+0.5*h*w-n A+(c-0.5*h)*w-n],'k');
Spitze(A+(c-0.5*h)*w-n,w,0.25*h,45*deg);
Schrift(A+0.5*c*w+0.5*n,'\it\bfw','HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot3,A+c*w,'.k','Markersize',30);
drawPolygon(@plot3,[A-h*w A+c*w],'k');
drawPolygon(@plot3,[A+c*w A+(d+h)*w],'k','linewidth',2.0);
Schrift(A+c*w,'{\itP}_0+{\itc\bfw}_{ }','HorizontalAlignment','left','VerticalAlignment','top')

drawPolygon(@fill3,[A+a*v+c*w A+5*(b+h)*v+c*w A+5*(b+h)*v+5*(d+h)*w A+a*v+5*(d+h)*w A+a*v+c*w],...
  0.75*[1 1 1],'edgecolor','none');
hold('off')
view(2)
axis('off')
axis('equal');
ax=[0 2.5 -2 0 A(3)+0.1*h*[-1 1]];
axis(ax);
print('-depsc','EbeneParallelspat-2')

figure('numbertitle','off','name','Parallelspat');
drawPolygon(@plot3,A,'ok','Markersize',10);
hold('on')

n=0.25*h*[-v(2);v(1);0];
drawPolygon(@plot3,[A+0.5*h*v-n A+(a-0.5*h)*v-n],'k');
Spitze(A+(a-0.5*h)*v-n,v,0.25*h,45*deg);
Schrift(A+0.5*a*v-1.5*n,'\it\bfv','HorizontalAlignment','left','VerticalAlignment','middle');
drawPolygon(@plot3,[A+a*v A+b*v],'.k','Markersize',30);
drawPolygon(@plot3,[A-h*v A+a*v],'k');
drawPolygon(@plot3,[A+a*v A+b*v],'k','linewidth',2.0);
drawPolygon(@plot3,[A+b*v A+(b+h)*v],'k');
Schrift(A,'{\itP}_{0}','HorizontalAlignment','right','VerticalAlignment','top')
Schrift(A+a*v-[0;0;0.3]*h,'_{ }{\itP}_0+{\ita\bfv}','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(A+b*v-[0;0;0.3]*h,'_{ }{\itP}_0+{\itb\bfv}','HorizontalAlignment','left','VerticalAlignment','middle')

n=0.25*h*[-w(2);w(1);0];
drawPolygon(@plot3,[A+0.5*h*w-n A+(c-0.5*h)*w-n],'k');
Spitze(A+(c-0.5*h)*w-n,w,0.25*h,45*deg);
Schrift(A+0.5*c*w+0.5*n,'\it\bfw','HorizontalAlignment','center','VerticalAlignment','top');
drawPolygon(@plot3,[A+c*w A+d*w],'.k','Markersize',30);
drawPolygon(@plot3,[A-h*w A+c*w],'k');
drawPolygon(@plot3,[A+c*w A+d*w],'k','linewidth',2.0);
drawPolygon(@plot3,[A+d*w A+(d+h)*w],'k');
Schrift(A+c*w,'{\itP}_0+{\itc\bfw}_{ }','HorizontalAlignment','left','VerticalAlignment','top')
Schrift(A+d*w,'{\itP}_0+{\itd\bfw}_{ }','HorizontalAlignment','center','VerticalAlignment','top')

n=0.75*h*[-u(2);u(1);0];
drawPolygon(@plot3,[A+0.5*h*u-n A+(e-0.5*h)*u-n],'k');
Spitze(A+(e-0.5*h)*u-n,u,0.25*h,45*deg);
Schrift(A+0.5*e*u+4*n,'   \it\bfu','HorizontalAlignment','left','VerticalAlignment','baseline');
drawPolygon(@plot3,[A+e*u A+f*u],'.k','Markersize',30);
drawPolygon(@plot3,[A-h*u A+e*u],'k');
drawPolygon(@plot3,[A+e*u A+f*u],'k','linewidth',2.0);
drawPolygon(@plot3,[A+f*u A+(f+h)*u],'k');
Schrift(A+e*u,'_{  }{\itP}_0+{\ite\bfu}_{ }','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(A+f*u,'_{  }{\itP}_0+{\itf\bfu}_{ }','HorizontalAlignment','left','VerticalAlignment','middle')

drawPolygon(@fill3,[A+a*v+c*w+e*u A+b*v+c*w+e*u A+b*v+d*w+e*u A+a*v+d*w+e*u A+a*v+c*w+e*u],0.75*[1 1 1],'edgecolor','none');
drawPolygon(@fill3,[A+a*v+c*w+f*u A+b*v+c*w+f*u A+b*v+d*w+f*u A+a*v+d*w+f*u A+a*v+c*w+f*u],0.75*[1 1 1],'edgecolor','none');
drawPolygon(@fill3,[A+a*v+c*w+e*u A+b*v+c*w+e*u  A+b*v+c*w+f*u A+a*v+c*w+f*u],0.625*[1 1 1],'edgecolor','none');
drawPolygon(@fill3,[A+a*v+d*w+e*u A+b*v+d*w+e*u  A+b*v+d*w+f*u A+a*v+d*w+f*u],0.625*[1 1 1],'edgecolor','none');
drawPolygon(@fill3,[A+a*v+c*w+e*u A+a*v+d*w+e*u A+a*v+d*w+f*u A+a*v+c*w+f*u],0.875*[1 1 1],'edgecolor','none');
drawPolygon(@fill3,[A+b*v+c*w+e*u A+b*v+d*w+e*u A+b*v+d*w+f*u A+b*v+c*w+f*u],0.875*[1 1 1],'edgecolor','none');
hold('off')
view(2)
axis('off')
axis('equal');
ax=[-1 2.5 -1.5 0 0.5 1.2];
axis(ax);
print('-depsc','EbeneParallelspat-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
