function [xinterp,yinterp,reverse] = plotLineOnRegion(x,y,row,col,displayAxis)
%Plots the selected line onto the current region
% Inputs: x and y coordinates of the original region
%         row and col of the new sub-region
%         axis to display line on
% Outputs: Interpolated x and y coordinates of the line on the new region
%          Flag to indicate a reversal of the direction of the cross-section plot
% Kevin Baggett Wed Aug  8 17:20:55 UTC 2001

sidex=abs(diff(x));
sidey=abs(diff(y));
reverse=0;

if sidey > 100 & sidex > 100
     xcoord=[col,1];
     ycoord=[row,1];
     xinterp=[1:1:col]';
     if x(1)>x(2)
         xinterp=flipud(xinterp);
         reverse=1;
     else
         xcoord=fliplr(xcoord);
     end
     if y(1) < y(2)
        ycoord=fliplr(ycoord);
     end
     yinterp=floor(interp1(xcoord,ycoord,xinterp));
 elseif sidey < 100 % case of near horizontal lines
     xcoord=[1;col];
     ycoord=[(row - diff(y))/2; (row + diff(y))/2];
     xinterp=[1:1:col]';
     if x(1) > x(2)
          xcoord=flipud(xcoord);
          xinterp=flipud(xinterp);
          reverse=1;
     end 
     yinterp=floor(interp1(xcoord,ycoord,xinterp));
     
 elseif sidex < 100 % case of near vertical lines
     xcoord=[(col - diff(x))/2; (col+diff(x))/2];
     ycoord=[1;row];
     yinterp=[1:1:row]';
     if y(1)>y(2)
        ycoord=flipud(ycoord);
        yinterp=flipud(yinterp);
        reverse=1;
     end
     xinterp=floor(interp1(ycoord,xcoord,yinterp));
 end
 
 axes(displayAxis);
 hold on;
 plot(xcoord,ycoord,'m');

% add letters to plot 
num_points=length(xinterp);
pts_by_3=floor(num_points/3);
xpts=[xinterp(1) xinterp(pts_by_3) xinterp(2*pts_by_3) xinterp(num_points)];
ypts=[yinterp(1) yinterp(pts_by_3) yinterp(2*pts_by_3) yinterp(num_points)];
text(xpts,ypts,{'A'; 'B'; 'C'; 'D'},'Color','r');