function drawArrow(x,y,color,lwidth)

% DRAWARROW(x,y)
% Draw an arrow with head at point x(1), y(1) and tail at point x(2), y(2)
% in the current figure.  If x and y are matrices, drawArrow treats each
% column as a separate arrow.
% 
% Author: Christine Alvarado
% Date: Oct 21, 2005
%


xdiff = x(1,:) - x(2,:)
ydiff = y(1,:) - y(2,:)
theta = 90 - atand(ydiff ./ xdiff)

less = find(xdiff < 0);
theta(less) = theta(less)+180

len =  0.1 .* sqrt(xdiff .* xdiff + ydiff .* ydiff)

alpha = 90 - theta - 45;
alpha2 = theta - 45;

newx1 = x(1,:) - len .* cosd(alpha);
newy1 = y(1,:) - len .* sind(alpha);

newx2 = x(1,:) - len .* sind(alpha2);
newy2 = y(1,:) - len .* cosd(alpha2);

arrowheadx1 = [x(1,:) ; newx1];
arrowheady1 = [y(1,:) ; newy1];

arrowheadx2 = [x(1,:) ; newx2];
arrowheady2 = [y(1,:) ; newy2];

line(x,y,'Color',color,'LineWidth', lwidth);
line(arrowheadx1, arrowheady1, 'Color', color, 'LineWidth', lwidth);
line(arrowheadx2, arrowheady2, 'Color', color, 'LineWidth', lwidth);

