One possibility for the situation where one gets a local min is as follows. Intersect the region with a sphere of radius slightly larger than the given distance, centered at the query point. Now one can repeat with a better chance of getting the global min. Moreover one can get an approximation by meshing the subregion, extracting vertices, and using ordinary Nearest
to find the closest vertex to the query point. I show this below.
Here is the original setup and the local min found.
pt = {-0.5, 4};
region = ImplicitRegion[y - x^2 == 0, {x, y}];
pt1 = RegionNearest[region, pt]
dist = EuclideanDistance[pt1, pt]
(* Out[64]= {1.83399714916, 3.36354556229}
Out[65]= 2.41921825051 *)
If we use a subregion comprised of points at most slightly further away, then we get a better minimal distance/closer point. We could of course go in the direction of being more exclusive, by taking a radius that excludes the point we found, and for some purposes that might be better. But I'll leave that for others to consider.
region2 =
ImplicitRegion[
y - x^2 == 0 && ({x, y} - pt).({x, y} - pt) <= 1.01*dist^2, {x, y}];
pt2 = RegionNearest[region2, pt]
dist2 = EuclideanDistance[pt2, pt]
(* Out[68]= {-1.90556930822, 3.63119438843}
Out[69]= 1.45314922129 *)
Here is the meshing approach mentioned above.
ptlist = MeshCoordinates[DiscretizeRegion[region2]];
pt3 = First[Nearest[ptlist, pt]]
dist3 = EuclideanDistance[pt3, pt]
(* Out[71]= {-1.92080363722, 3.68948661277}
Out[72]= 1.4543388667 *)
One will note that it does give a good approximation to the globally closest point. This method might be slow, due to meshing algorithm internals, or too coarse, due to quality of mesh, so caveat emptor.
After writing the above I realized some of this is built in. One can just discretize the original region and do RegionNearest
on that.
pt4 = RegionNearest[DiscretizeRegion[region], pt]
dist4 = EuclideanDistance[pt4, pt]
(* Out[74]= {-1.90493346777, 3.63315045973}
Out[75]= 1.45203878531 *)
Again, there might be speed issues and or artifacts from quality of the discretization such as a result that is too close (if discretization goes outside the boundary of the actual region) or too far (if discretization is too coarse to capture sufficient detail).