# (A&Q)How to speed up RegionMember [duplicate]

I have to say the RegionMember is very slow

poly = Polygon[{{1, 0}, {0, 1}, {0, 0}}];
SeedRandom[1234];
pts = RandomReal[{0, 1}, {10^4, 2}];
RegionMember[poly, #] & /@ pts // Tr // AbsoluteTiming


{18.1054,5073 False+4927 True}

How to speed up it?

You can also reduce overhead by passing all points at once or by creating a RegionMemberFunction:

RegionMember[poly, pts] // Tr // AbsoluteTiming

{0.00396, 5073 False + 4927 True}

rm = RegionMember[poly];
rm[pts] // Tr // AbsoluteTiming

{0.002928, 5073 False + 4927 True}

rm = RegionMember[poly];
rm /@ pts // Tr // AbsoluteTiming

{0.06013, 5073 False + 4927 True}

• Thanks,this is good lesson to me. :) – yode Dec 18 '16 at 18:00

I found a kernel function,which will not be abandon and be change arbitrarily in future version I think.So I want to share it in here.

## GraphicsPolygonUtilsInPolygonQ

poly = Polygon[{{1, 0}, {0, 1}, {0, 0}}];
SeedRandom[1234];
pts = RandomReal[{0, 1}, {10^4, 2}];
GraphicsPolygonUtilsInPolygonQ[poly, #] & /@ pts //
Tr // AbsoluteTiming


{0.0582609,5073 False+4927 True}

• @corey979 It always give False confusing me still.And it is a kernel function,too. – yode Dec 18 '16 at 18:33