0
$\begingroup$

My problem is as follows:

I have an exact rational polygon created using ConvexHullMesh and given a rational point I need Mathematica to decide exactly if it is inside the polygon or not. I feel like this should be possible to implement. RegionMember seeemingly works and doesn't work depending how it is implemented. Let's consider a toy case:

ConvexHullMesh[{{-1,1},{1,1},{1,-1},{-1,-1}}] This is of course a square and checking polygon coordinates we can see that Mathematica treats this exactly:

PolygonCoordinates[ConvexHullMesh[{{-1, 1}, {1, 1}, {1, -1}, {-1, -1}}]]

gives

{{-1, -1}, {-1, 1}, {1, -1}, {1, 1}}

Originally I hoped that RegionMember might work, but it does not. Looking at the documentation we can see that it treats the point you are testing numerically, and not exactly.Thus

RegionMember[ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}], {1+1/10000000000000, 1}] returns True which is false. Is there anything I co do so Mathematica checks it exactly?

One Idea I had was instead of making it a region, make it a polygon. Oddly enough RegionMember[Polygon[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}], {1 +1/10000000000000,1}] returns False. Which is great but I am not sure why this worked and the other one did not, It seems it should treat the point numerically in both cases.

In any case, if making it a polygon works, which I am not sure if it does. I could simply consider RegionMember[Polygon@PolygonCoordinates@ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}],{1 +1/10000000000000,1}] However, not only does this seem roundabout, it also does not always work. Polygon cares about the order of points, so I would need to order polygon coordinates appropriately which I do not know how to do.

Any help would be appreciated.

$\endgroup$

1 Answer 1

2
$\begingroup$

You can use RegionWithin[region, Point @ pt]:

RegionWithin[ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}], 
 Point @ {1 + 1/10000000000000, 1}]
False
RegionWithin[ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}], 
 Point@{1, 1}]
True

Alternatively, use SignedRegionDistance:

SignedRegionDistance[ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}],
    {1 + 1/10000000000000, 1}] <= 0.
False
SignedRegionDistance[ConvexHullMesh[{{-1, 1}, {-1, -1}, {1, -1}, {1, 1}}],
     {1, 1}] <= 0.
True
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.