1
$\begingroup$

I want to check whether a point $(x,y)$ belongs to a square region whose x-interval is $[x_1,x_2]$ and y-interval is $[y_1,y_2]$. I defined the 2d region as

Interval[{{x1,x2},{y1,y2}}]

and checked for membership as

IntervalMemberQ[Interval[{{x1,x2},{y1,y2}}],{x,y}]

but the output is always {False, False} no matter the input. For example

IntervalMemberQ[Interval[{{0,1},{0,1}}],{0.5,0.5}]
{False,False} (*output*)

What is going wrong? What is the correct way to deal with this problem? Thanks in advance for any help.

$\endgroup$
  • 3
    $\begingroup$ Interval is strictly 1D. Do RegionMember[ImplicitRegion[0 <= x <= 1 && 0 <= y <= 1, {x, y}], {0.5, 0.5}]. $\endgroup$ – corey979 Nov 17 '16 at 11:03
  • $\begingroup$ @Kuba , corey979 Unfortunately Mathematica 9.0 does not seem to have that function. $\endgroup$ – Deep Nov 17 '16 at 11:08
  • $\begingroup$ There are some older topics: mathematica.stackexchange.com/q/9405/5478 $\endgroup$ – Kuba Nov 17 '16 at 11:12
  • $\begingroup$ @Kuba Thank you very much. I shall check it out. $\endgroup$ – Deep Nov 17 '16 at 11:17
2
$\begingroup$

Interval is for 1-dimensional regions only. For a 2D region, one can do

RegionMember[ImplicitRegion[0 <= x <= 1 && 0 <= y <= 1, {x, y}], {0.5, 0.5}]

True

or, in pre-RegionMember versions, by threading over each dimension with

MapThread[IntervalMemberQ, {{Interval[{0, 1}], Interval[{0, 1}]}, {0.5, 0.5}}]

{True, True}

To get a definite answer, apply And:

And @@ MapThread[IntervalMemberQ, {{Interval[{0, 1}], Interval[{0, 1}]}, {0.5, 0.5}}]

True

Contrary, with {0.5, 1.5}:

MapThread[IntervalMemberQ, {{Interval[{0, 1}], Interval[{0, 1}]}, {0.5, 1.5}}]

{True, False}

so that

And @@ MapThread[IntervalMemberQ, {{Interval[{0, 1}], Interval[{0, 1}]}, {0.5, 1.5}}]

False

$\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.