function TransformQuader

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

close('all')
deg=pi/180;
A=[3;2;1];
B=A+[5;0;0];
C=A+[5;3;0];
D=A+[0;3;0];
E=A+[0;0;4];
F=A+[5;0;4];
G=A+[5;3;4];
H=A+[0;3;4];
plotQua([A B C D E F G H]);
hold('on')
Q=[A B C D E F G H
  1 1 1 1 1 1 1 1];
V1=[eye(3) -A;0 0 0 1];
Q1=V1*Q;
t=120*deg;
V2=[cos(t) 0 -sin(t) 0
  0      1  0      0
  sin(t) 0  cos(t) 0
  0      0  0      1];
Q2=V2*Q1;
V3=[eye(3) A;0 0 0 1];
Q3=V3*Q2;
V4=[eye(3) [-1;2;0];0 0 0 1];
Q4=V4*Q3;
plotQua(Q4)
Schrift(Q(1:3,1),'\itA','HorizontalAlignment','right','VerticalAlignment','top')
Schrift(Q(1:3,2),'\itB','HorizontalAlignment','right','VerticalAlignment','top')
Schrift(Q(1:3,3),'\itC  ','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(Q(1:3,4),'\itD','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(Q(1:3,5),'\it E','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(Q(1:3,6),'\itF ','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(Q(1:3,7),'\itG ','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(Q(1:3,8),'\it H','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(Q4(1:3,1),' \itA*','HorizontalAlignment','left','VerticalAlignment','baseline')
Schrift(Q4(1:3,2),'\itB*','HorizontalAlignment','center','VerticalAlignment','bottom')
Schrift(Q4(1:3,3),'\itC* ','HorizontalAlignment','right','VerticalAlignment','middle')
Schrift(Q4(1:3,4),' \itD*','HorizontalAlignment','center','VerticalAlignment','top')
Schrift(Q4(1:3,5),' \itE*','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(Q4(1:3,6),' \itF*','HorizontalAlignment','center','VerticalAlignment','bottom')
Schrift(Q4(1:3,7),' \itG*','HorizontalAlignment','left','VerticalAlignment','middle')
Schrift(Q4(1:3,8),' \itH*','HorizontalAlignment','left','VerticalAlignment','middle')
view(165,28);
axis('equal')
axis([min(xlim) 9 0 10 0 4.01]);
ax=axis;
xg=floor(ax(1)):ceil(ax(2));
yg=floor(ax(3)):ceil(ax(4));
zg=floor(ax(5)):ceil(ax(6));
for x=xg(1:end-1)
  Schrift([x;ax(4);ax(5)],int2str(x),'FontSize',18,'HorizontalAlignment','center','VerticalAlignment','top')
end
for y=yg(1:end-1)
  Schrift([ax(2);y;ax(5)],[int2str(y) ' '],'FontSize',18,'HorizontalAlignment','right','VerticalAlignment','middle')
end
for z=zg(2:end)
  Schrift([ax(2);ax(3);z],[int2str(z) ' '],'FontSize',18,'HorizontalAlignment','right','VerticalAlignment','middle')
end
[Xg,Yg]=meshgrid(xg,yg);
Zg=repmat(ax(5),size(Xg));
plot3(Xg,Yg,Zg,Xg',Yg',Zg','color',0.75*[1 1 1]);
[Xg,Zg]=meshgrid(xg,zg);
Yg=repmat(ax(3),size(Xg));
plot3(Xg,Yg,Zg,Xg',Yg',Zg','color',0.75*[1 1 1]);
[Yg,Zg]=meshgrid(yg,zg);
Xg=repmat(ax(1),size(Yg));
plot3(Xg,Yg,Zg,Xg',Yg',Zg','color',0.75*[1 1 1]);
h=0.6;
X=max(xlim);
Y=max(ylim);
Z=max(zlim);
axis(axis+[0 3*h 0 h 0 h]);
plot3([0 X+2.5*h],[0 0],[0 0],'k','erase','xor')
plot3([0 0],[0 Y+0.5*h],[0 0],'k','erase','xor')
plot3([0 0],[0 0],[0 Z],'k','erase','xor')
Spitze([X;0;0],[1;0;0],h,30*deg,'k');
Spitze([0;Y;0],[0;1;0],h,30*deg,'k');
Spitze([0;0;Z],[0;0;1],h,30*deg,'k');
Schrift([X;0;0.5*h],'{ }\itx','HorizontalAlignment','left','VerticalAlignment','bottom')
Schrift([0.75*h;Y;0],'\ity','HorizontalAlignment','right','VerticalAlignment','bottom')
Schrift([0;0;Z],'\itz','HorizontalAlignment','center','VerticalAlignment','bottom')
grid('off')
hold('off')
axis('off')
axis(ax);
print('-depsc','TransformQuader')

function plotQua(Q);
A=Q(1:3,1);
B=Q(1:3,2);
C=Q(1:3,3);
D=Q(1:3,4);
E=Q(1:3,5);
F=Q(1:3,6);
G=Q(1:3,7);
H=Q(1:3,8);
plot3([A(1) B(1) C(1) D(1) A(1)],[A(2) B(2) C(2) D(2) A(2)],[A(3) B(3) C(3) D(3) A(3)],'k',...
  [E(1) F(1) G(1) H(1) E(1)],[E(2) F(2) G(2) H(2) E(2)],[E(3) F(3) G(3) H(3) E(3)],'k',...
  [A(1) E(1)],[A(2) E(2)],[A(3) E(3)],'k',...
  [B(1) F(1)],[B(2) F(2)],[B(3) F(3)],'k',...
  [C(1) G(1)],[C(2) G(2)],[C(3) G(3)],'k',...
  [D(1) H(1)],[D(2) H(2)],[D(3) H(3)],'k')

function Schrift(P,txt,varargin)
text(P(1),P(2),P(3),txt,'FontName','TimesNewRoman','FontSize',20,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)],...
      varargin{:});
  end
end
