function d = p18_fd ( p )

%*****************************************************************************80
%
%% p18_fd() is a signed distance function for problem 18.
%
%  Modified:
%
%    21 August 2008
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real P(NP,1:2), one or more points.
%
%  Output:
%
%    real D(NP), the signed distance of each point to the boundary of the region.
%
  r1 = +1.0;
  r2 = +1.0;
  c1 = [ -2.0, 0.0 ];
  c2 = [ +2.0, 0.0 ];
%
%  Let the rectangle definition penetrate all the way to the center of the circles.
%
  w = 2.0;
  h = 1.0 / 3.0;
  d1 = sqrt ( ( p(:,1) - c1(1) ).^2 + ( p(:,2) - c1(2) ).^2 ) - r1;
  d2 = sqrt ( ( p(:,1) - c2(1) ).^2 + ( p(:,2) - c2(2) ).^2 ) - r2;
  d3 = drectangle ( p, -w, +w, -h, +h );

  d = min ( d1, min ( d2, d3 ) );

  return
end
