1
$\begingroup$

I have a list of regions and want to find which of those regions a certain point belongs to. My best attempt works, but only after throwing an error:

list = {Rectangle[{0, 0}], Rectangle[{1, 0}], Rectangle[{2, 0}]};
Position[list, _?(RegionMember[#, {3, 0}] &), {1}]
(*RegionMember::A correctly specified region expected at position 1 of RegionMember[List,{3,0}].*)
(*{{3}}*)

It also seems to work surprisingly slowly on a real use case, and I'm wondering if this is because of the error. Note that I ideally do need the actual position, so using Pick[] probably won't help. In my particular usage, only one of the polygons in the list will contain the point in question. Any suggestions?

$\endgroup$

1 Answer 1

1
$\begingroup$
Position[RegionMember[#, {3, 0}] & /@ list, True]

{{3}}

$\endgroup$
1
  • $\begingroup$ Beauty! Thanks! $\endgroup$
    – Shane
    Jul 19, 2017 at 22:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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