image thumbnail
from plot3rgb by Siddharth Ray
Plot a colored 3 D line changing its color with distance in the space.

plot3rgb(P)
function plot3rgb(P)
%-DESCRIPTION------------------------------------------------------------------------
% This function plot a colored 3-dimensional line of a set of given points. The plot 
% varies its color in a form,  x axis as red, y as green and z axis as blue. 
% So basically if the plot proceeds in x-axis it will colored as red, if proceed in 
% y-axis it is colored as green and if proceed in z-axis then its colored as blue.   

% INPUT: It take a matrix that contains a set of vectors.

whitebg('k');
k=1;
hold on
for c=1:size(P,1)
 
    x= (P(k+1,1)-P(k,1));
    y= (P(k+1,2)-P(k,2));
    z= (P(k+1,3)-P(k,3));
    ty= sqrt(x^2+y^2+z^2);
    x= x/ty;  x=x^2;
    y= y/ty;  y=y^2;
    z= z/ty;  z=z^2;
    plot3([P(k,1) P(k+1,1)],[P(k,2) P(k+1,2)],[P(k+1,3) P(k+1,3)],'color',[x y z])
   
end
%saveas(gcf,'sidoo','jpg')

Contact us