# How to determine whether a point is within a polygon in Mathematica 10

In Mathematica 9, I was able to use the function GraphicsMeshInPolygonQ to determine whether a given point was within a polygon. How do I do this in Mathematica 10?

What I actually want to do is RegionPlot only the regions where my data has support. I used to define

data2 = Flatten[Table[{i, j, Sqrt[i^2 + j^2]}, {i, 1, 20}, {j, i/2, i, i/6}], 1];
supports = data2[[All, 1 ;; 2]];
<< ComputationalGeometry
pol = supports[[ConvexHull[supports]]];
inPol = GraphicsMeshInPolygonQ[pol, #] &;


and could then use

RegionPlot[(Sqrt[x^2 + y^2] < 10) && inPol[{x, y}], {x, 0, 20}, {y, 0, 10}]


in order to plot a function (in the actual application it will be an interpolating function) only on the interesting region.

In Mathematica 10, GraphicsMeshInPolygonQ doesn't seem to exist anymore, or works differently.

• That's because the function is in a different context in version 10: GraphicsPolygonUtilsInPolygonQ[]. The context change was already noted in this previous answer. Commented Nov 12, 2015 at 3:04

You can use ConvexHullMesh to generate a geometric region to give as a plotting domain to RegionPlot.

data2 = Flatten[Table[{i, j, Sqrt[i^2 + j^2]}, {i, 1, 20}, {j, i/2, i, i/6}], 1];
supports = data2[[All, 1 ;; 2]];

RegionPlot[Sqrt[x^2 + y^2] < 10, {x, y} ∈ ConvexHullMesh[supports]]


More in detail, here is the relationship between the original RegionPlot with no restrictions (in grey), the convex hull of the supports (green), and the resulting plot shown above (red):

Show[
{
ConvexHullMesh[supports, MeshCellStyle -> {{2} -> Opacity[0.5, Green]}],
RegionPlot[Sqrt[x^2 + y^2] < 10, {x, 0, 20}, {y, 0, 20}, PlotStyle -> LightGray, BoundaryStyle -> Dashed],
RegionPlot[Sqrt[x^2 + y^2] < 10, {x, y} ∈ ConvexHullMesh[supports], PlotStyle -> Red]
},
Axes -> True
]


• I like that I can actually define the plotting region as the supported region, saving me a lot of hassle with extrapolation going wrong. Commented Nov 12, 2015 at 12:15

In v10 instead of GraphicsMeshInPolygonQ, you would use the more versatile RegionMember.

Rewriting your code to use it:

inPol = RegionMember[Polygon@pol, #] &

RegionPlot[(Sqrt[x^2 + y^2] < 10) && inPol[{x, y}], {x, 0, 20}, {y, 0, 10}]
`