# How to calculate the length of the sides of a rectangle given the diagonal coordinates

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.

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

• 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. – Akshay Srinivasan Jan 30 '18 at 20:17
• You are completely wrong. Given a hypotenuse, there are infinitely many different pairs of legs that will make a right triangle with it. – B. Goddard Jan 30 '18 at 20:41
• Woops you are right – 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}$

• I've added to my answer. – Emilio Novati Jan 30 '18 at 20:07
• 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 – Akshay Srinivasan Jan 30 '18 at 20:10
• In other words what is d and a in terms of xa, ya, xb, yb numbers values – Akshay Srinivasan Jan 30 '18 at 20:11
• 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. – Emilio Novati Jan 30 '18 at 20:13
• 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. – Akshay Srinivasan Jan 30 '18 at 20:23

This is related to Thales' theorem

https://en.wikipedia.org/wiki/Thales%27s_theorem

See the infinite many different pairs of legs here

https://en.wikipedia.org/wiki/Thales%27s_theorem#Proof