({{, (RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction])[reg,…] 
represents a function whose values give whether a point is in a region reg or not.}})

OpenersNotesSection(Spacer1)Details

(RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]) works like (RefLink[Function, paclet:ref/Function]).

(RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]) is generated by (RefLink[RegionMember, paclet:ref/RegionMember])[reg].

(RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction])[reg,…][{x,y,…}] gives (RefLink[True, paclet:ref/True]) if the numerical point {x,y,…} is a member of the constant region reg where (RefLink[ConstantRegionQ, paclet:ref/ConstantRegionQ])[reg] is (RefLink[True, paclet:ref/True]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (22)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

(RefLink[RegionMember, paclet:ref/RegionMember]) for a region generates a (RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]):

mf=RegionMember[Disk[]]

Apply function repeatedly for member tests:

Map[mf,RandomReal[{-1,1},{10,2}]]

OpenersExampleSection1(Spacer1)Scope  (16)

OpenersExampleSubsection0(Spacer1)Special Regions  (5)

Use (RefLink[RegionMember, paclet:ref/RegionMember]) to generate a (RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]):

ℛ=Polygon[{{0,0},{2,-1},{1,0},{2,1}}];
Region[ℛ]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

mf[{{1/2,0},{3,4}}]

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^3];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{ℛ,AbsolutePointSize[1.6],{col,Point/@pts}\[Transpose]}]

Test for points within an (RefLink[Interval, paclet:ref/Interval]):

ℛ=Interval[{0,1}];
gr=NumberLinePlot[ℛ]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[{{-0.5,1.5}}],100];
col=mf[pts]/.{False->Gray,True->Red};

gp=Graphics[{AbsolutePointSize[1.6],Table[{col[[i]],Point[{pts[[i,1]],3}]},{i,100}]}];

Show[gr,gp,PlotRange->All]

Test for points within a (RefLink[Disk, paclet:ref/Disk]):

ℛ=Disk[{0,0},2];
Region[ℛ]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^3];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{ℛ,AbsolutePointSize[1.6],{col,Point/@pts}\[Transpose]}]

Test for points within a (RefLink[Cylinder, paclet:ref/Cylinder]):

ℛ=Cylinder[{{0,0,0},{2,2,2}},2];
gr=Graphics3D[{Opacity[0.3],ℛ},Boxed->False,Lighting->"Neutral"]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^3];
col=mf[pts]/.{False->Gray,True->Red};

Show[gr,Graphics3D[{AbsolutePointSize[2],{col,Point/@pts}\[Transpose]}]]

Regions in (ℝ^n):

ℛ=Ball[{0,0,0,0,0,0,0},1];
pl=RandomReal[{0,0.7},{7,7}];

mf=RegionMember[ℛ];

mf/@pl

OpenersExampleSubsection1(Spacer1)Formula Regions  (3)

A union of two disks as an (RefLink[ImplicitRegion, paclet:ref/ImplicitRegion]):

ℛ=ImplicitRegion[(x^2)+(y^2)≤4∨(((x-3))^2)+(y^2)≤3,{x,y}];
DiscretizeRegion[ℛ,{{-6,6},{-2,2}}]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

mf[{{1,1},{2,2}}]

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

A union of two cylinders as an (RefLink[ImplicitRegion, paclet:ref/ImplicitRegion]):

ℛ=ImplicitRegion[(x^2)+(y^2)≤2∨(((x-2))^2)+(y^2)≤1,{x,y,{z,0,2}}];
DiscretizeRegion[ℛ,{2{-2,2},{-2,2},{0,2}}]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics3D[{AbsolutePointSize[1.6],{col,Point/@pts}\[Transpose]}]

A disk represented as a (RefLink[ParametricRegion, paclet:ref/ParametricRegion]):

ℛ=ParametricRegion[{r Cos[θ],r Sin[θ]},{{r,0,1},{θ,0,2π}}];

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

OpenersExampleSubsection2(Spacer1)Mesh Regions  (6)

(RefLink[MeshRegion, paclet:ref/MeshRegion]) in 1D:

ℛ=DelaunayMesh[RandomReal[1,{10,1}]]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

mf[{{1/2},{3}}]

2D:

ℛ=DelaunayMesh[RandomReal[2,{50,2}]]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

3D:

ℛ=DelaunayMesh[RandomReal[1,{100,3}]]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics3D[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

(RefLink[BoundaryMeshRegion, paclet:ref/BoundaryMeshRegion]) in 1D:

ℛ=ConvexHullMesh[RandomReal[1,{10,1}]]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

mf[{{1/2},{3}}]

2D:

ℛ=ConvexHullMesh[RandomReal[1,{50,2}]]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

3D:

ℛ=ConvexHullMesh[RandomReal[1,{100,3}]]

mf=RegionMember[ℛ]

(RefLink[MeshCoordinates, paclet:ref/MeshCoordinates]) are always members of the region:

AllTrue[MeshCoordinates[ℛ],mf]

OpenersExampleSubsection3(Spacer1)Derived Regions  (2)

(RefLink[RegionIntersection, paclet:ref/RegionIntersection]) of two regions:

ℛ=RegionIntersection[Disk[{0, 0}, 1],Disk[{0,1}, 1]];

Region[ℛ]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

mf[{{0,1},{3,4}}]

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

(RefLink[TransformedRegion, paclet:ref/TransformedRegion]):

ℛ=TransformedRegion[Disk[{0,0},1],ScalingTransform[{3,2}]];

DiscretizeRegion[ℛ,{{-3,3},{-2,2}}]

mf=RegionMember[ℛ]

Apply it to a list of points to test membership:

pts=RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^4];
col=mf[pts]/.{False->Gray,True->Red};

Graphics[{AbsolutePointSize[1],{col,Point/@pts}\[Transpose]}]

OpenersExampleSection3(Spacer1)Applications  (3)

Generate points on a region by filtering a uniform set of points:

ℛ=BoundaryDiscretizeGraphics[CountryData["US","Polygon"]];

Get the region bounds:

bounds=RegionBounds[ℛ];

Uniformly sample over the bounding box of the region:

pts=RandomVariate[UniformDistribution[bounds],10^4];

Select member points:

mpts=Select[pts,RegionMember[ℛ]];

Visualize member points:

Graphics[{AbsolutePointSize[1],Point[mpts]}]

Color points based on which region they belong to:

(Subscript[ℛ, 1])=BoundaryDiscretizeGraphics[CountryData["US","Polygon"]];
(Subscript[ℛ, 2])=BoundaryDiscretizeGraphics[CountryData["Canada","Polygon"]];

Create membership functions for each:

mf1=RegionMember[(Subscript[ℛ, 1])];
mf2=RegionMember[(Subscript[ℛ, 2])];

Generate points over a bounding box of both regions:

pts=RandomVariate[UniformDistribution[RegionBounds[RegionUnion[(Subscript[ℛ, 1]),(Subscript[ℛ, 2])]]],10^4];

Visualize:

Graphics[{AbsolutePointSize[1],{Red,Point@Select[pts,mf1]},{Blue,Point@Select[pts,mf2]},{Black,Point@Select[pts,!mf1[#]&&!mf2[#]&]}}]

Use random points in a region to perform Monte Carlo integration:

ℛ=ImplicitRegion[2≤(x^2)+(y^2)≤4,{x,y}];
mf=RegionMember[ℛ];
pts=Select[RandomVariate[UniformDistribution[RegionBounds[ℛ]],10^5],mf];

Evaluate a function at each sample point and take their average:

f[x_,y_]:=(x^3)+(y^4);
intVal=Mean[f@@@pts]*RegionMeasure[ℛ]

Compare with the exact value:

Integrate[f[x,y],{x,y}∈ℛ]

%//N

OpenersExampleSection4(Spacer1)Properties & Relations  (1)

(RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]) is generated by (RefLink[RegionMember, paclet:ref/RegionMember]):

mf=RegionMember[Disk[{0,0},1]]

mf@RandomReal[1,{7,2}]

OpenersExampleSection5(Spacer1)Possible Issues  (1)

(RefLink[RegionMemberFunction, paclet:ref/RegionMemberFunction]) can only be generated for (RefLink[ConstantRegionQ, paclet:ref/ConstantRegionQ]) regions:

ℛ=Disk[{x,y},r]

ConstantRegionQ[ℛ]

RegionMember[ℛ]

Generate the member function for a specific instance:

mf=RegionMember[ℛ/.{x->0,y->2,r->1}]

mf[{{0,1},{10,10}}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[RegionMember, paclet:ref/RegionMember])  ▪  (RefLink[RegionDistanceFunction, paclet:ref/RegionDistanceFunction])  ▪  (RefLink[RegionDistance, paclet:ref/RegionDistance])  ▪  (RefLink[RegionNearest, paclet:ref/RegionNearest])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Region Properties and Measures, paclet:guide/GeometricPropertiesAndMeasures])}})}})