Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a program that lets users draw custom 4-sided shapes using java 2d. I want to calculate the angles inside the shapes so I can rotate text to the proper angle and label each side.

I am trying to calculate all angles of a 4-sided polygon given the length of all 4 sides. I found a formula using law of cosines for a cyclic quadrilateral, but I don't know that all of my shapes will be cyclic since they are user defined and can be any 4 points in a 2d coordinate system.

Is my only option to find the diagonals and start piecing it together with law of cosines for each triangle?

share|cite|improve this question
Don't you have the coordinates of the vertices? If so, the easiest option would be to find the angle of each side with, say, the $x$-axis, and then subtract appropriately. – Rahul Mar 18 '12 at 8:35
I do have the coordinates of all 4 points. Can you elaborate on how this would be done? – jimdrang Mar 18 '12 at 8:40
$$\alpha = \arctan \left|\frac{m_1-m_2}{1+m_1m_2}\right|$$ , where : $$m_1=\frac{y_D-y_A}{x_D-x_A} , m_2=\frac{y_B-y_A}{x_B-x_A} $$ – pedja Mar 18 '12 at 8:50
up vote 5 down vote accepted

The lengths don't determine the angles: for example with all sides equal you have a rhombus, where the angle at any vertex could be anything in the interval $(0, \pi)$.

share|cite|improve this answer
So you are saying what I want to do is not possible? Even if I can rule out special cases like all sides being equal? – jimdrang Mar 18 '12 at 8:48
That's correct. Imagine having four girders of the right lengths, and attaching the ends with joints that can turn freely. The frame that you'd have would not be rigid; you could vary all the angles. Therefore, you can't calculate the angles given the four sides, unless you have an extra piece of information (like knowing the length of one diagonal; or knowing that the quadrilateral is cyclic). – user22805 Mar 18 '12 at 9:01
Ok, I'm having trouble figuring out if you are telling me this is not possible at all or just the way I stated the question. So if I change the question title to given 4 (x,y) coordinates, it would be possible using the right triangles I can create using the x and y axis? – jimdrang Mar 18 '12 at 9:15
@jimdrang: If you know the coordinates, then the points are fixed, and so are the angles. You can find the angles using the cosine formula, as you said. – Beni Bogosel May 13 '12 at 16:29

If you know the (x,y) coordinates, then you also the lengths of the diagonals and you can use the law of cosines to find the angles.

share|cite|improve this answer

To find the fourth coordinate of a 4 sided polygon except for trapezoid and kite but for rhombus, square, rectangle and parallelogram.

You can simply add first 2 given opposite coordinates then Subtract it by the opposite unknown coordinates.

E.g if ABCD is a rectangle and the coordinates are A(-4;8) B(-10;0) C(6;-12) D(x;y).

Determine the coordinates of D







share|cite|improve this answer
It usually is not necessary to give your name, date, or email. The site records all this information. – Vladhagen Aug 19 '14 at 20:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.