What is the law of cosines?
The law of cosines, also called the cosine rule, relates the three side lengths of a triangle to the cosine of its angles. It works for acute, right, and obtuse triangles, so it extends the Pythagorean theorem beyond right triangles.
Here, a and b are the two sides enclosing angle C, while c is the side opposite C. The same relationship can be written cyclically for the other two sides.
The formula appears in all three equivalent forms: a² = b² + c² − 2bc cos A, b² = a² + c² − 2ac cos B, and c² = a² + b² − 2ab cos C.
Law of cosines formulas
Solving for a side
Solving for an angle
The side forms correspond to the SAS situation, while the inverse-cosine forms solve angles from SSS data. CalculatorSoup lists all three side and angle forms and the associated triangle quantities.
Geometric interpretation: the cosine correction
Imagine dropping an altitude from the vertex at angle C. The projection of one side onto the other introduces a term involving cos C. That projection is what separates the cosine rule from the simple right-triangle relationship.
Another way to see the same relationship is through coordinates: place one vertex at the origin, place a second on the x-axis, and express the third point using sine and cosine. Expanding the distance formula produces the same cosine-rule expression. Omni Calculator presents both the trigonometric-height and distance-formula routes, along with other proof approaches.
Step-by-step examples
Example 1 — SAS: find the third side
Suppose a = 5, b = 7, and the included angle is C = 60°.
c² = 25 + 49 − 70(0.5) = 39
c = √39 ≈ 6.245
The calculator also reports the area using K = ½ab sin C and the perimeter using P = a + b + c. CalculatorSoup gives the same standard triangle perimeter and area relationships alongside the cosine rule.
Example 2 — SSS: find an angle
Let a = 4, b = 5, and c = 6. To find angle A:
A = arccos((25 + 36 − 16)/60)
A = arccos(0.75) ≈ 41.41°
This matches the SSS workflow described by Omni Calculator. Once two angles are known, the third can also be obtained from the 180° angle sum.
Acute, right, and obtuse triangles
C < 90° — acute
cos C is positive, so 2ab cos C is positive and is subtracted from a²+b². Therefore c² is smaller than a²+b².
C = 90° — right
cos 90° = 0, so the correction disappears and c² = a²+b². The law of cosines becomes the Pythagorean theorem.
C > 90° — obtuse
cos C is negative, so subtracting 2ab cos C adds a positive amount. The opposite side becomes longer than √(a²+b²).
C → 180°
The triangle approaches a straight line and c approaches a+b. The area approaches zero.
How to check whether a triangle is valid
For three side lengths, the triangle inequality must hold:
For SAS, the computed side is generated directly from the cosine rule. For SSS, the inverse-cosine argument should remain between −1 and 1 apart from tiny floating-point rounding. The calculator clamps only microscopic numerical drift and otherwise reports invalid input rather than manufacturing a triangle.
| Check | Meaning | Expected result |
|---|---|---|
| a+b>c | Two sides must exceed the third | True |
| |a−b|<c | Third side must exceed the side difference | True |
| −1≤cos C≤1 | Inverse cosine must be defined | True |
| A+B+C=180° | Angle consistency | 180° |