0
$\begingroup$

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.

  • 0
    What exactly do you mean by formulation? Are you looking for an algorithm?2012-03-21
  • 0
    I am looking for a mathematical relation between a rectangle properties and points positions.2012-03-21
  • 0
    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$?2012-03-21
  • 0
    @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?2012-03-21
  • 0
    @TannerL.Swett: yes, exactly.2012-03-21
  • 0
    @AndréNicolas: my work is related to the network not game programming. however, I suppose that I have a big rectangle area which is divided equally to the small rectangles.(grid shape)2012-03-21
  • 0
    @AndréNicolas: now I need to decide if two points belong to the same rectangle.2012-03-21
  • 0
    If your rectangle has base $a$ and height $b$, but you are allowed to move it freely sideways or up/down, the condition is $|x_1-x_2|\le a$ **and** $|y_1-y_2|\le b$.2012-03-21
  • 0
    @AndréNicolas: Thanks. However, I don't think that is practical for my real problem.2012-03-21
  • 1
    @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?2012-03-21
  • 0
    If the two points are in the same rectangle (wherever that rectangle may be) then $$\lfloor\frac{x_1}{a}\rfloor = \lfloor\frac{x_2}{a}\rfloor \text{ and } \lfloor\frac{y_1}{b}\rfloor = \lfloor\frac{y_2}{b}\rfloor. $$2012-03-21

1 Answers 1