% parallel coordinate 3D plane

clf
clear all

npoints=330;

%need two parameter for a plane
t=rand(1,npoints);
u=rand(1,npoints);

%the plane
pos(1,:)= t;  %x
pos(2,:)= -.5*t+.5*u ;  %y
pos(3,:)= 1.1*u + .0*rand(1,npoints) ; 
s=t;

map=jet(10) ;
%s=r;
%s= sqrt( (pos(1,:)-deltax).^2 + ...
%  (pos(2,:)-deltay).^2 +...
%  pos(3,:).^2);
s = 10*(s - min(s))/(max(s)-min(s))+1 ;

%===============
subplot(3,1,1)
hold on
for i = 1:npoints
    if (s(i)<12)
        cindex = min( fix(s(i)), 10);
        plot(pos(:,i), 'color', map(cindex,:) ); %
    end
end

axisx = [1,3; 1,1; 2,2; 3,3; ]';
axisy = [0,0; 0,1; 0,1; 0,1; ]';
line(axisx, axisy, 'color', 'k');

%================

subplot(3,1,2)

set(gca,'color',[1 1 1])
box on
view(22,63)
axis vis3d
xlabel('x');ylabel('y');zlabel('z');
hold on
for i = 1:npoints
    cindex = min( fix(s(i)), 10);
    plot3(pos(1,i),pos(2,i),pos(3,i),...
        'markerfacecolor', map(cindex,:),...
        'markersize',1.5 ,'color',map(cindex,:),...
        'marker','o',...
        'linewidth',3)
end
rotate3d on

%===============

subplot(3,1,3)

hold on
%use pairs of points on the plane to compute slopes between various axes
%and draw a bunch of lines
for i=1:  npoints-1
    m1(i)=(pos(2,i+1)-pos(2,i))/(pos(1,i+1)-pos(1,i));
    m2(i)=(pos(3,i+1)-pos(3,i))/(pos(2,i+1)-pos(2,i));
    b1(i)=pos(2,i) - m1(i)*pos(1,i);
    b2(i)=pos(3,i) - m2(i)*pos(2,i);
    line([1+1./(1-m1(i))  2+1./(1-m2(i));],...
         [b1(i)./(1-m1(i))  b2(i)./(1-m2(i))])
end

axisx = [1,3; 1,1; 2,2; 3,3; ]';
axisy = [0,0; 0,1; 0,1; 0,1; ]';
%line(axisx, axisy, 'color', 'k');
set(gca,'xlim',[0 3],'ylim',[-2 2])



