Check if a point is inside a rectangle (not knowing the coordinates, but knowing distances to vertices)

2.4k Views Asked by At

I have to solve the following problem: I have 4 points (A, B, C, D) which form a rectangle, but I do not know their coordinates. I have another point (X), I do not know its coordinates either, but I know the distances between point X and all other 4 points (XA, XB, XC, XD). I need to be able to tell if X lies within a rectangle formed by A, B, C, D. Any help appreciated.

4

There are 4 best solutions below

2
On BEST ANSWER

It seems it is impossible to know whether X is inside for sure. For example, if we had a rectangle ABCD and a point X inside of it, WLOG so that the vertical distance from X to CD is less than the vertical distance from X to AB, creating a new rectangle ABEF with EF parallel to AB and CD, but EF underneath X with the same vertical distance creates a new rectangle with exactly the same distances to the vertices, but with X outside.

(Low picture quality, which is why I hesitate to put a picture. But I also thought that my above explanation was sort of unclear, so I posted this too.)

enter image description here

0
On

It's not possible in general:

A . . . . . D . . A'
.           .     .
.           .     .
B . . . . . C . . B'

Let $X$ be the centre of $ABA'B'$. Then $XA=XA'$ and $XB=XB'$, and of course $XC=XC$ and $XD=XD$. But for suitable choice of $C$ and $D$, $X$ is inside $ABCD$ but not $A'B'CD$.

0
On

For any point $X$ inside the rectangle, except the rectangle's center, there exists another rectangle, which has the same vertices-to-X distances, but does not contain $X$. You can construct it by mirroring one of the rectangle's edges by an axis parallel to the edge and passing through $X$.

The opposite is also true: you can make a reverse construction for the $X$ outside a rectangle to find an appropriate rectangle containing $X$. If $X$ lies 'opposite to some edge', not to a corner, that is, when $X$ lies between two parallel lines containing two opposite sides of a rectangle, one side mirroring will suffice. If $X$ is 'opposite to a corner', that is it lies in the angle vertical to the rectangle's corner (see https://commons.wikimedia.org/wiki/File:Vertical_angles.svg), one needs two such mirrorings for two adjacent sides of the rectangle.

As a result,

  • if three of the four $AX$, $BX$, $CX$, $DX$ distances are equal, then $X$ is a center of the $ABCD$ rectangle (and the fourth distance must be equal to those three, too), so you know it is inside.
  • In any other case you can't tell whether $X$ is inside or outsde the rectangle, because there exist two rectangles $ABCD$, $A'B'C'D'$ with the same distances of their respective vertices to the given point: $AX=A'X$, $BX=B'X$, $CX=C'X$, $DX=D'X$, one rectangle containing $X$ and the other one missing it.
1
On

I assume that the four given points are as given as four trees in a landscape forming a nondegenerate rectangle. If your question could not be decided this would mean that we have four different circles intersecting in at least two different points $P$, $Q$. But this would imply that the four circles all have their center on the median $m$ of $P$ and $Q$, contrary to assumption.