function perspective();

vert = [-1 -1 -1; 1 -1 -1; 1 1 -1; -1 1 -1; -1 -1 1; 1 -1 1; 1 1 1; -1 1 1];

vert = trans(pi/3,vert);

vtk_axis([-2,2,-2,2,-.5,6]);
draw(vert);
end

return

function draw(v)

faces = [1 2 3 4;1 5 6 2;2 6 7 3;5 8 7 6;1 4 8 5;4 3 7 8];

B= [-1/sqrt(2)    1/sqrt(6)    1/sqrt(3)
          0      -2/sqrt(6)    1/sqrt(3)
     1/sqrt(2)    1/sqrt(6)    1/sqrt(3)];

X=zeros(1,5);
Y=zeros(1,5);
Z=zeros(1,5);

v(:,3)=v(:,3)+4;

for i=1:size(faces,1)
    for j=1:size(faces,2)
        X(j)=v(faces(i,j),1);
        Y(j)=v(faces(i,j),2);
        Z(j)=v(faces(i,j),3);
    endfor
    X(5)=X(1);
    Y(5)=Y(1);
    Z(5)=Z(1);
    vtk_line3(X',Y',Z',"r");
    vtk_poly3(X,Y,Z,"Opacity",1);
endfor

vtk_plot3(0,0,0,"r");
vtk_poly3([-1,1,1,-1],[-1,-1,1,1],[1 1 1 1],"g","Opacity",0.2);
for i=1:(size(v,1)-1)
   vtk_line3([0,v(i,1)]',[0,v(i,2)]',[0,v(i,3)]',"y");
endfor

for i=1:size(faces,1)
    for j=1:size(faces,2)
        X(j)=v(faces(i,j),1)/v(faces(i,j),3);
        Y(j)=v(faces(i,j),2)/v(faces(i,j),3);
        Z(j)=1;
    endfor
    X(5)=X(1);
    Y(5)=Y(1);
    Z(5)=Z(1);
    u=v(faces(i,2),:)-v(faces(i,1),:);
    w=v(faces(i,4),:)-v(faces(i,1),:);
    n=cross(w,u);
    if (n(3)<0)
      vtk_line3(X',Y',Z',"r");
      vtk_poly3(X,Y,Z,"Opacity",1);
    endif
endfor

function v=trans(a,vr);

B= [-1/sqrt(2)    1/sqrt(6)    1/sqrt(3)
          0      -2/sqrt(6)    1/sqrt(3)
     1/sqrt(2)    1/sqrt(6)    1/sqrt(3)];

R=[cos(a) -sin(a) 0;sin(a) cos(a) 0;0 0 1]; 

T = B*R*inv(B);

v = (T*vr')';

return
