Given a 2-D Region $\Omega$, i.e.
RegionQ[ω] && RegionDimension[ω] == 2
is True, and a pair of points p1 and p2 such that
RegionMember[ω, p1] && !RegionMember[ω, p2]
is True, I need to find the intersection of the Line[{p1, p2}] with the RegionBoundary[ω]. Ideally the point-intersection nearest to p1 if possible and if not so much expensive.
Ideally, the method should give:
- an exact answer if the region is "exact" and if analytically possible;
- an answer with a
Precisionand/orAccuracysimilar to the input for "numerical" regions; - an answer
psuch thatRegionMember[RegionBoundary[ω, p]givesTrue.
None of the above is strictly required; I can accept to obtain an approximate answer even for an exact region; in that case a way to eventually specify the Precision/Accuracy sought would be helpful.
The first basic strategy I tried is based on the following function:
RegionNearest[RegionIntersection[Line[{p1, p2}], RegionBoundary[ω]], p1]
This probably satisfies all the requirements above but is very very slow even for something like 100 pairs of points.
Following another post here I also tried something like:
r = RegionIntersection[Line[{p1, p2}];
Block[{x, y}, {x, y} /. (RegionMember[r, {x, y}] // Reduce // ToRules)]
which is not as robust, but is faster, even if not enough.
The third way I tried is a kind of bisection algorithm:
q = RegionMember[ω];
Module[{n1=N@p1, n2=N@p2, nm},
FixedPoint[(If[q[nm=Mean[{n1,n2}]],n1=nm,n2=nm];nm)&,n1]
]
This approximately works, is fast enough. Unfortunately I don't know how to control the precision of the output and the answer I get often doesn't satisfy the third requirement.
Is there a way to get better results?
I considered also working on a someway discretized version of the region (I think I can control the accuracy of the mesh and so the accuracy of the answer), but I don't know how to start and if it would be useful.


