# “Way” to decide if points are in a rectangle.

Suppose $P_1=(x_1,y_1)$, $P_2=(x_2,y_2)$ are two points.

Also suppose that we have a rectangle which we just know the value of its sides $a$ and $b$.

I am looking for some kind of formulation which can show whether $P_1$ and $P_2$ are inside of rectangle or not.

-
What exactly do you mean by formulation? Are you looking for an algorithm? – Aryabhata Mar 21 '12 at 18:31
I am looking for a mathematical relation between a rectangle properties and points positions. – sepideh Mar 21 '12 at 18:45
Suppose $a$ is $1$, $b$ is $100$, $P_1 = (0, 0)$, and $P_2 = (10, 10)$. What are you asking in this case? Are you asking whether or not there exists a $1$ by $100$ rectangle containing both $P_1$ and $P_2$? – Tanner Swett Mar 21 '12 at 18:49
@sepideh: Many people interested in game programming think of a rectangle as having sides parallel to the edges of the screen. Is this what you mean by rectangle, or can a rectangle have arbitrary orientation? – André Nicolas Mar 21 '12 at 18:59
@sepideh: If we don't know where the rectangle is (you only gave us the side lengths) how can we know whether the points are inside it? – Ross Millikan Mar 21 '12 at 20:28

Without knowing the position of the rectangle, it is impossible to tell whether any particular point lies inside of it. The most one can say (as the commenters pointed out), is that the conditions $$|x_1-x_2|\le a \quad \text{and } \ |y_1-y_2|\le b$$ are necessary for the two points to belong to the same (axes-aligned) rectangle $a\times b$. It is also sufficient if you are allowed to move the rectangle.