# Calculating the Location of a Point Relative to a Rectangle

Is it possible to calculate the location of a point (x, y) relative to a rectangle, knowing only only the differences between the distances from each corner of the rectangle to the point?

In the diagram, the lengths of blue lines are known, and the top-left corner of the rectangle is on the edge of the circle.

Edit: The top-left corner of the rectangle can be assumed to be (0,0), with the right side at a a positive x.

• Is this a math problem? Or a programming problem? – user49763 Mar 17 '14 at 12:42
• It is going to be implemented in code, so a programming problem ...I think? It's right on the line. – Builder_K Mar 17 '14 at 12:45
• What variables do you have? Can you make a list and add it to the question? – Simon Minshall Mar 17 '14 at 13:47
• It is a math problem really. If the lengths of the three blue lines are known, then the x,y point is unique (if it exists). – assylias Mar 17 '14 at 14:03
• Just to clarify, nothing else is known, including the size of the rectangle. – Builder_K Mar 17 '14 at 14:16

You cannot without knowing the location of the rectangle. Namely, for any circle, you could always compute two points $(x,y)$ and $(x',y')$ in the circle, and two rectangles $R$ and $R'$ out side of the circle such that the distance between $(x,y)$ and each corner $r_{1},...,r_{4}$ of $R$ is equal to the distance between $(x',y')$ and each corner of $R'$, $r_{1}',...,r_{4}'$.

In other words, there always exists $R$ and $R'$ such that $d((x,y),r_{j})=d((x',y'),r_{j}')$ for $j=1,2,3,4$. Then whenever you are given the distances $d((x,y),r_{j})$, if you choose rectangle $R$ you get the point $(x,y)$ and if you choose the rectangle $R'$ you get the point $(x',y')$. A simple counter example can be found by assuming your circle is the unit circle, and the point is $(1,0)$. Then take any rectangle(not intersecting the unit circle) to be $R$ and the reflection of $R$ over the $y$-axis to be $R'$. If you assume the rectangle is $R$ you get the point $(1,0)$ and if you assume the rectangle is $R'$ you get $(-1,0)$. Thus, without any additional information to distinguish between whether the rectangle is $R$ or $R'$ you cannot solve the problem.

• "location of a point (x, y) relative to a rectangle", does that not allow it to be solved? Assume the location of the top-left corner of the rectangle is (0,0). – Kent Mar 17 '14 at 16:26
• I get it now, thank you! – Kent Mar 17 '14 at 16:54

Suppose you know the first corner is at $(1,1)$ and $S$ is the unit circle. Then take $R=((1,1),(1,2),(2,1),(2,2))$ and $R'=((1,1),(2,1)(1,2),(2,2))$ (literally the same rectangle but relabeling the 2nd and 3rd vertices). Then denote by $r_{j}$ and $r'_{j}$ the distance between $z$ the point in question and the $j$th corner of $R$ and $R'$ respectively. Then, if $z=(0,1)$ and you use $R$ you get $(r_{1},r_{2},r_{3},r_{4})=(1,2,\sqrt{2},\sqrt{5})$ and if $z=(1,0)$ and you use $R'$ you get $(r'_{1},r'_{2},r'_{3},r'_{4})=(1,2,\sqrt{2},\sqrt{5})$. Hence, using different $R$'s with the same distances gives you different points. Also, this example shows that even if you know one corner of the rectangle(e.g. the first corner is at $(1,1)$) and the length and width of the rectangle, it still is not enough to find the point.

If you know which point corresponds to which distance, than you should be able to arrive at an answer. Draw circles of the appropriate radius through each of the points, and look for any intersection. So long as the original circle is outside the rectangle you should have an intersection. With just two distances given it would be indeterminate (you could have two intersections. With the third point given you should only have a single intersection.

• Are you assuming that the size of the rectangle is known? – Kent Mar 17 '14 at 18:45
• I don't believe that is a requirement. It sounds to me what your talking about is Trilateration. – user136074 Mar 17 '14 at 20:50
• It's for a codding project, I have 3 strings attached to motors. – Kent Mar 17 '14 at 21:31
• Then it sounds to me like you know the locations of the points on the rectangles which would be your motors.. In which case measuring each of the strings should allow you to compute the location of the point using trilateration. – user136074 Mar 18 '14 at 22:42
• Nope! I know the location of the point, and I need to be able to calculate the distance to an arbitrary point (0-1, 0-1) on the rectangle. – Kent Mar 19 '14 at 15:16