function stemhandle = vec2d(x,y,varargin)
%
%function vec2d(x,y)

stemhandle = [];

scalefactor = 0.3; %2;
a = scalefactor*0.12;
aa= scalefactor*0.10;
b = scalefactor*0.05;

n = length(x);
if n~=length(y),
  disp('Premature return from vec2d sketching procedure.');
  return;
end;

arclen = sum( ((x(2:n)-x(1:n-1)).^2 + (y(2:n)-y(1:n-1)).^2).^(1/2) );
if (arclen < 0.0001)
  disp('Warning from vec2d: arrowhead may be too big for this tiny vector.');
end;

% Prototype arrowhead, tip at origin:
ahx = [0,-a,-aa,-a,0];
ahy = [0, b,  0,-b,0];

% Find angle of the last segment in the given x, y lists:
th = atan2(y(n)-y(n-1),x(n)-x(n-1));

% Set scale for arrowhead size
smallest = 0.8;
biggest  = 1.6;
scale = min( [max([smallest,arclen]),biggest] );

% Scaled and rotated arrowhead, tip still at origin:
aho = scale*[cos(th),-sin(th);sin(th),cos(th)]*[ahx;ahy];

% Draw the points, then add arrowhead.
% (Wrapper preserves status of "ishold" -- probably pointless.)

holdstatus = false;
if (ishold), holdstatus = true; end;

stemhandle = plot(x,y,varargin{:});
stemrgb = get(stemhandle,'Color');
hold on;
fill(x(n)+aho(1,:), y(n)+aho(2,:), stemrgb ,'EdgeColor','none');

if ~holdstatus, hold off; end;

