function [est_north, est_east] = closest_intersect(prev_n, prev_e, na, ea, nb, eb, ra, rb)

% function to call circle_intersect() and return the solution that is
% closest to prev_n, prev_e.  If there is no intersection, 
% then (for now) the answer is [NaN, NaN]

north = [NaN ; NaN];
east = [NaN ; NaN];
num_solns = 0;

%% mean_thresh = 10;   
mean_thresh = 1;         % 4/25/95 jleonard change from 10

[north,east, num_solns]=circle_intersect( na, ea, nb, eb, ra, rb );

if (num_solns == 0) 
  est_east = NaN;
  est_north = NaN;	
elseif (num_solns == 1) 
  est_east = east(1);
  est_north = north(1);	
elseif (num_solns == 2) 
  % first check dist between the 2 solutions, if < mean_thresh meters
  % use the mean      
  dist12 = dist(north(1), east(1), north(2), east(2));
  if (dist12 < mean_thresh) 
    % disp([' closest_intersect: dist12 = ', num2str(dist12), ' using mean']);
    est_east = 0.5 * ( east(1) + east(2) );
    est_north = 0.5 * ( north(1) + north(2) );
 else 
    % Find the solution closest to the previous solution
    dist1 = dist(prev_n, prev_e, north(1), east(1));
    dist2 = dist(prev_n, prev_e, north(2), east(2));
    if (dist1<dist2) 
      est_east = east(1);
      est_north = north(1);	
    else
      est_east = east(2);
      est_north = north(2);	  
    end
  end
else 
  disp(['error in closest_intersect, num_solns = ', num2str(num_solns)]);
end

