Law of Cosines Calculator
Result
Angle A
- Angle B
- 53.13 °
- Angle C
- 90.00 °
The law of cosines calculator takes the three sides of a triangle and returns its three angles. The relation is the one British textbooks call the cosine rule; the two names mean the same equation. The input is the three-sides case, usually written SSS for side-side-side, and it always determines the triangle completely — so unlike the law of sines page next door, this triangle solver has nothing to choose and no second solution to weigh up. The law itself is the extension of the Pythagorean theorem that works when there is no right angle: in a right triangle the square on the longest side equals the sum of the squares on the other two, and in every other triangle that sum has to be corrected by a term involving the cosine of the angle across from the side you started with. Written for one angle, it reads: the square of a side equals the squares of the other two minus twice their product times the cosine of the angle opposite. Solving that for the angle gives the working form this page computes — the cosine of each angle from the three sides, then the angle itself. Three sides always determine a triangle. The only questions the three numbers can raise are whether they fit together at all. They have to satisfy the triangle inequality: each side shorter than the sum of the other two, which is the statement that the shortest path between two points is the straight one. If one side is longer than the other two put together, no triangle has those three sides and this page says so rather than returning a negative angle. If one side is exactly equal to the sum of the other two, the triangle is squeezed flat onto a line and the three angles come out as 0, 0 and 180 — a real limit rather than an error, and the last row of the table below. One thing to expect from the output: the three angles are each computed independently from the three sides and each rounded to two decimal places, so they can add up to 180.01 or 179.99 instead of exactly a straight angle. Nothing has gone wrong when that happens, and the limitations paragraph below says why.
Eight triangles and the three angles that go with each
| Side a (cm) | Side b (cm) | Side c (cm) | Angle A (°) | Angle B (°) | Angle C (°) |
|---|---|---|---|---|---|
| 3 | 4 | 5 | 36.87 | 53.13 | 90 |
| 5 | 5 | 5 | 60 | 60 | 60 |
| 5 | 12 | 13 | 22.62 | 67.38 | 90 |
| 8 | 15 | 17 | 28.07 | 61.93 | 90 |
| 7 | 8 | 9 | 48.19 | 58.41 | 73.4 |
| 4 | 5 | 6 | 41.41 | 55.77 | 82.82 |
| 2 | 3 | 4 | 28.96 | 46.57 | 104.48 |
| 3 | 4 | 7 | 0 | 0 | 180 |
Side lengths in centimetres and angles in degrees, in the same order the panel prints them, so a row can be checked against the page in one glance. Three rows are right triangles — three-four-five, five-twelve-thirteen and eight-fifteen-seventeen — and they are the rows where the law of cosines reduces to the Pythagorean theorem, which is why one angle in each is a clean 90 with nothing rounded. The second row is equilateral and the only row where all three readings are exact; the fifth and sixth are an ordinary pair of acute triangles, and the seventh is obtuse, with the angle across from the longest side reading 104.48. That seventh row is also the only one whose three angles do not quite add to a straight angle: 28.96 and 46.57 and 104.48 come to 180.01, because each was rounded on its own. The last row is the boundary case — three plus four is exactly seven, so the triangle is flat, the corners have collapsed onto a single line, and the angles read 0, 0 and 180. Nothing in the table is typed in by hand — every row is computed the same way the panel computes it, so the table and the answer you get from the boxes above can never drift apart.
Formula
a² = b² + c² − 2bc·cos A cos A = (b² + c² − a²) ÷ 2bc A = arccos((b² + c² − a²) ÷ 2bc)
- a, b, c
- The three sides of the triangle, in any unit you like as long as all three use the same one. Side a is the one across from angle A, and the other two follow the same pattern
- A
- The angle across from side a — the one this form of the law recovers. The other two angles come from the same formula with the letters rotated
- cos A
- The cosine of that angle, which is what the three sides give you directly. Recovering the angle from it is a separate step, and it is the step that puts the reading between zero and one hundred and eighty degrees
- 2bc
- Twice the product of the two sides that meet at the angle. This is the correction term the Pythagorean theorem does not have, and it is what makes the law work when no angle is a right angle
Use this page when you have all three sides of a triangle and want its angles — a plot of land measured along its boundary, a bracket cut to three lengths, a triangle drawn on a map where you can pace the sides but cannot sight the corners. It is the only one of the two triangle pages that needs no angle to start with, which is exactly when the law of sines is no help at all. It is also the quickest way to find out whether three lengths can form a triangle before you build anything: type them in, and either three angles come back or a message tells you which side is too long. If you have two sides and the angle between them, that is the side-angle-side shape, which belongs to the triangle page and lands on the same theorem from the other end. If you want the area of the triangle rather than its angles, the three sides are also all Heron's formula needs. And if what you have is a side and two angles, or two sides and an angle that is not between them, the law of sines page is the one to use.
Worked examples
The three-four-five triangle, where one angle is exactly a right angle
- Take the angle across from the side of length 5
- The squares of the other two sides add to 9 plus 16, which is 25
- The correction term is twice 3 times 4 times the cosine of that angle; setting the whole expression equal to 25 leaves the cosine at zero, so the angle is 90 degrees
- The other two angles follow from the same formula with the letters rotated, and come out 36.87 and 53.13
The page's own starting values, and the triangle every reader has met before. It is the case where the law of cosines and the Pythagorean theorem agree: the correction term vanishes because the cosine of a right angle is zero, and the formula collapses back to the theorem. The two acute angles are the pair that shows why this page can be trusted — they add to 90 exactly, and the third angle is a clean 90 with nothing rounded.
An equilateral triangle, where nothing is rounded away
- All three sides are equal, so all three angles are equal as well
- The three angles add to 180 degrees
- 180 divided by 3 is exactly 60, so every reading is 60 with no decimal places lost
Three equal sides give three equal angles, and since they have to add to a straight angle each one is exactly sixty degrees — the only row in the table below where all three readings are exact and none of them is zero. It is also a useful check on the formula: the correction term here is twice 5 times 5 times the cosine of sixty, which is 25, and 25 plus 25 minus 25 is 25, which is the square of the third side. The formula agrees with itself.
An obtuse triangle, sides 2, 3 and 4
- Take the angle across from the longest side, which is the one that may be obtuse
- The squares of the other two sides add to 4 plus 9, which is 13
- Subtract the square of the longest side, 16, leaving minus 3
- Divide by twice the product of the other two sides, which is 12, giving a cosine of minus 0.25
- The angle whose cosine is minus 0.25 is 104.48 degrees, and the other two follow at 28.96 and 46.57
The angle across from the longest side is the obtuse one, and that is a rule rather than a coincidence: the largest side faces the largest angle, and once one side is longer than the square root of the sum of the squares of the other two the angle facing it passes a right angle. Here 4 is longer than the square root of thirteen, so the angle across from it is 104.48 degrees. Note what the three readings add up to: 180.01, a hundredth over a straight angle, because each was rounded separately. The limitations paragraph below is about exactly this.
Three sides that only just fit, 3, 4 and 7
- Three plus four is seven, exactly the length of the longest side
- The correction term reaches its extreme, and the cosine of the angle across from the longest side comes out at minus one
- The angle whose cosine is minus one is 180 degrees, and the other two collapse to zero
Seven is exactly three plus four, so the triangle has no room left: the two shorter sides lie flat along the longest one and the figure is a straight line with the corners collapsed onto it. This is the boundary the triangle inequality allows, and it is printed rather than refused because it is a genuine limit — the angles really do go to 0, 0 and 180. Push either short side up by any amount at all and a real triangle appears, with positive angles that grow as the sides separate; push it down and the page reports that no triangle has those sides.
Limitations
Three limits worth stating plainly. The three angles are computed independently from the three sides and each is rounded to two decimal places, so they will often add up to 180.01 or 179.99 rather than exactly a straight angle — a two-three-four triangle is off by a hundredth, as the third example above shows. The alternative would be to compute two angles and derive the third by subtraction, which always sums to exactly 180 — but it breaks the symmetry from the other end: an isosceles triangle with two sides of 3 and a base of 3.3 has two base angles of 56.63 degrees, and that method prints them as 56.63 and 56.64, because the third angle is subtracted from two values that were already rounded. A hundredth of a degree of drift was judged the smaller lie. Second, the sides must satisfy the triangle inequality: every one of them shorter than the sum of the other two. This page refuses anything that fails it, and accepts the boundary case where one side is exactly the sum of the other two, which produces a flat triangle with angles of 0, 0 and 180 degrees. Third, the page prints no side lengths and no area. The sides are not missing — they are the three numbers you typed, and the triangle is fully determined by them, so there is nothing further to report. If the area is what you want, that is a different output of the same three numbers.
Frequently asked questions
- What is the law of cosines used for?
- For the two jobs the Pythagorean theorem cannot do. First, when you have all three sides of a triangle and want its angles, which is what this page does: the theorem only produces an angle when one of them is already a right angle, and the extra correction term is what makes it work in every other triangle. Second, when you have two sides and the angle between them and want the third side — the triangle page next door uses it that way. The two directions are the same equation read from either end.
- Why do my three angles add up to 180.01 instead of 180?
- Because each angle is computed from the three sides on its own and then rounded to two decimal places, and three separate roundings need not cancel out. It is not a bug and it does not mean the triangle is impossible; it means the printed readings are each within a hundredth of a degree of the true angle. The alternative — compute two angles and get the third by subtracting them from 180 — always sums exactly, but it rounds two angles and then subtracts them, so an isosceles triangle with two base angles of 56.63 degrees comes out as 56.63 and 56.64, which is a worse lie in a different direction.
- Do any three side lengths make a triangle?
- No. Each side has to be shorter than the other two put together, which is the triangle inequality: the shortest route between two corners is the side joining them directly, so going round by way of the third corner cannot be shorter. If one side is longer than the sum of the other two, this page refuses the input rather than returning an impossible angle. If it is exactly equal, the triangle is flat and the angles come out as 0, 0 and 180, which the page accepts because that is a real boundary rather than a mistake.
- Why does this page give three angles and no side lengths?
- Because the three sides are the input. A triangle with three given sides is completely determined — there is exactly one shape it can be, up to sliding and turning it around — so printing the sides back would be repeating what you just typed. What the page adds is the part you could not see: where the corners are, which is the three angles. The same three numbers also give the area, and that is a separate tool.
- How do I know if the triangle has an obtuse angle?
- Look at the longest side. If its square is larger than the sum of the squares of the other two, the angle facing it is obtuse; if the two are equal, that angle is exactly a right angle; if it is smaller, all three angles are acute. The 2-3-4 triangle in the examples above is the obtuse case — sixteen against thirteen — and it is always the largest angle that turns obtuse, because the largest side faces the largest angle.
- When should I use this instead of the law of sines?
- Use this one when you know all three sides, or two sides and the angle between them. Use the law of sines when you know a side and the angle across from it together with one other piece, because that is the information the ratio of side to sine needs. The case where the two pages overlap is two sides and an angle that is not between them, and there the law of sines is the better tool — it is also the case where a triangle can have two different shapes, which this page never has to worry about.
References
- Law of Cosines — the relation between the three sides of a triangle and the cosine of one of its angles, and its reduction to the Pythagorean theorem — Wolfram MathWorld (United States)
- Triangle — the triangle inequality, the rule that the largest side faces the largest angle, and the degenerate cases — Wolfram MathWorld (United States)
- Trigonometric Functions — the sine, cosine and tangent of an angle, their ranges, and why recovering an angle from a cosine gives a value between zero and one hundred and eighty degrees — Wolfram MathWorld (United States)
- The Law of Cosines — the theorem worked through from first principles, with the side-angle-side and three-sides cases shown separately — Math is Fun (United Kingdom)