I have the top left corner and bottom right corner coordinates of a rectangle. The length of the diagonal is just the distance between the top left corner and bottom right corner. How can i solve for the length of the sides of the rectangle.

  • $\begingroup$ The absolute value of the difference in x coordinates and y coordinates respectively $\endgroup$ – Mike Jan 30 '18 at 19:52
  • $\begingroup$ Hint sketch picture and see how much the coordinates have changed. $\endgroup$ – Karl Jan 30 '18 at 19:53
  • $\begingroup$ What if it is rotated and not straight which is easy solution $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 19:54
  • $\begingroup$ By straight which is simple difference in x and y of points only applies if the rectangles sides are parallel to the axes $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 20:04
  • 1
    $\begingroup$ Then you have to provide some additional information: the coordinates of the diagonal do not specify the rectangle completely. $\endgroup$ – NickD Jan 30 '18 at 20:07

There are infinitely many answers with the information given. As you can easily imagine, there are lots of rectangles, of different sizes that have the same diagonal. Certainly, if the sides of the rectangle are $a$ and $b$, and the length of the diagonal is $d$, then $a^2+b^2=d^2$. You're trying to use one number $d$ to find two numbers $a$ and $b$. This should upset you, philosophically. To solve the problem, we need more information. Either the other diagonal, or perhaps you seek only integer solutions...?

  • $\begingroup$ Well a rectangle around the diagonal is 2 right angled triangles. While there are an infinite number of non right angled triangles there is only one rectangle for the given coordinates and 2 right angled triangles. So while there may be an infinite set of possible triangles there is only 2 right angled triangle side solutions for that diagonal. Try to draw an infinite number of rectangles for the same diagonal length and you will see its not possible. $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 20:17
  • $\begingroup$ You are completely wrong. Given a hypotenuse, there are infinitely many different pairs of legs that will make a right triangle with it. $\endgroup$ – B. Goddard Jan 30 '18 at 20:41
  • $\begingroup$ Woops you are right $\endgroup$ – Akshay Srinivasan Jan 31 '18 at 10:12

If the two points are $A(x_a,y_a)$ and $B=(x_b,y_b)$ than the sides of the rectangle with sides parallel to the coordinate axis are: $|x_b-x_a| $ and $|y_b-y_a|$.

If $d=\overline{AB}=\sqrt{(x_b-x_a)^2+(y_b-y_a)^2}$, a rectangle that has the sides not parallel to the axis can have a side of length $a \in (0,d)$ and the other side of length $b=\sqrt{d^2-a^2}$

  • $\begingroup$ I've added to my answer. $\endgroup$ – Emilio Novati Jan 30 '18 at 20:07
  • $\begingroup$ Can you explain a bit simpler I am not familiar with the math symbols. I need to write javascript code out of this so some pseudocode simple steps without math symbol jargon will help me a lot $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 20:10
  • $\begingroup$ In other words what is d and a in terms of xa, ya, xb, yb numbers values $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 20:11
  • $\begingroup$ If $d$ is the length of the diagonal, you can chose any value from $0$ to $d$ for the length of one side of the rectangle , and the the length of other side is given by Pitagora theorem. $\endgroup$ – Emilio Novati Jan 30 '18 at 20:13
  • $\begingroup$ Thanks for answer to d being diagonal length or distance between the points. I dont understand how to calculate the value of a i dont know what the notation means. $\endgroup$ – Akshay Srinivasan Jan 30 '18 at 20:23

This is related to Thales' theorem


See the infinite many different pairs of legs here



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.