function vectarrow(p0,p1,clr)
%Purpose: Arrowline 3-D vector plot.
%   Example:
%       3D vector
%       p0 = [1 2 3];   % Coordinate of the first point p0
%       p1 = [4 5 6];   % Coordinate of the second point p1
%       vectarrow(p0,p1)
%
%   Author: Rentian Xiong 04/18/2005
%   Modified by:Guofeng Yuan  02/04/2010

  if max(size(p0))==3
      if max(size(p1))==3
          x0 = p0(1);
          y0 = p0(2);
          z0 = p0(3);
          x1 = p1(1);
          y1 = p1(2);
          z1 = p1(3);
          colorplot=plot3([x0;x1],[y0;y1],[z0;z1]);   % Draw a line between p0 and p1
          set(colorplot,'Color',clr);
          p = p1-p0;
          alpha = 0.1;  % Size of arrow head relative to the length of the vector
          beta = 0.1;  % Width of the base of the arrow head relative to the length
          
          hu = [x1-alpha*(p(1)+beta*(p(2)+eps)); x1; x1-alpha*(p(1)-beta*(p(2)+eps))];
          hv = [y1-alpha*(p(2)-beta*(p(1)+eps)); y1; y1-alpha*(p(2)+beta*(p(1)+eps))];
          hw = [z1-alpha*p(3);z1;z1-alpha*p(3)];
          hold on
          arrowplot=plot3(hu(:),hv(:),hw(:),'HandleVisibility','off')  % Plot arrow head
          grid on
          xlabel('x','FontSize',18)
          ylabel('y','FontSize',18)
          zlabel('z','FontSize',18)
          set(arrowplot,'Color',clr);
          hold off;
          
      else
          error('p0 and p1 must have the same dimension')
      end
  else
      error('this function only accepts 3D vector')
  end