# How do I use the law of cosines?

Finds the third side of a triangle from two sides and the angle between them, an angle from three sides, or a side from two sides and an angle.

- Page: https://www.acalculator.org/math/law-of-cosines-calculator
- JSON spec: https://www.acalculator.org/math/law-of-cosines-calculator.json
- Version: c66e1bfc6c55

## Default answer

Example with the default inputs (Side a 5, Side b 7, Angle C 60 °): A triangle with sides 5 and 7 and the angle 60° between them has a third side of 6.244998.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| sideA | Side a | The length of side a, opposite angle A. |
| sideB | Side b | The length of side b, opposite angle B. |
| sideC | Side c | The length of side c, opposite angle C. |
| angle | Angle C | The angle between sides a and b, opposite side c. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| a | Side a | The length of side a, opposite angle A. |
| b | Side b | The length of side b, opposite angle B. |
| c | Side c | The length of side c, opposite angle C. |
| C | Angle C | The angle between sides a and b, opposite side c. |
| A | Angle A | The angle opposite side a. |
| B | Angle B | The angle opposite side b. |
| perimeter | Perimeter | The sum of the three sides: a + b + c. |
| area | Area | The area of the triangle, from Heron’s formula. |
| inradius | Inradius | The radius of the inscribed circle: area ÷ half the perimeter. |
| circumradius | Circumradius | The radius of the circumscribed circle: abc ÷ (4 × area). |

## Method

c² = a² + b² − 2ab cos C, where C is the angle between sides a and b.

## Assumptions

- Angles are between 0° and 180°; sides are more than 0, in any one unit.
- Two sides and the angle opposite one of them can fit two triangles (the ambiguous case): both answers are shown.
- Three sides must satisfy the triangle inequality: each side shorter than the other two together.
- Angles A and B, the area, and the radii come from the three typed values in stable forms (Kahan), so needle-like triangles keep their accuracy; the circumradius c ÷ (2 sin C) shows once in the ambiguous case.

## Worked examples

1. sideA = 5, sideB = 7, angle = 1.047198 gives sideC = 6.244998, perimeter = 18.244998, area = 15.155445.
2. sideA = 3, sideB = 4, angle = 1.570796 gives sideC = 5, A = 0.643501, area = 6, inradius = 1, circumradius = 2.5.
3. sideA = 5, sideB = 7, sideC = 8 gives angle = 1.427449, B = 1.047198, area = 17.320508.
4. sideB = 8, sideC = 7, angle = 1.047198 gives sideA = 5.
5. sideA = 5, sideB = 7, angle = 2 gives sideC = 10.155308.
6. sideB = 0.023707, sideC = 8,286.471048, angle = 0.039593 gives B = 0, circumradius = 104,672.850328. Source: Needle triangle (SSA) from docs/progress/WP-60-24.md, finding 1.
7. sideA = 0.001, sideB = 1,000, angle = 0.001 gives A = 0, area = 0.0005, circumradius = 499,999.583334.

## FAQ

### What is the Law of Cosines?

The Law of Cosines is a trigonometric formula that relates the lengths of the sides of a triangle to the cosine of one of its angles. It's an extension of the Pythagorean theorem for non-right triangles.

### When should I use the Law of Cosines?

Use the Law of Cosines when you have either: 1) Two sides and the included angle (SAS case) to find the third side, or 2) Three sides (SSS case) to find the angles. It also finds a side from two sides and an angle that is not between them (SSA case).

### What's the difference between SAS and SSS cases?

SAS (Side-Angle-Side) means you know two sides and the angle between them. SSS (Side-Side-Side) means you know all three sides. The calculator handles both cases automatically.

### Does the calculator support SSA (Side-Side-Angle)?

Yes. SSA can result in the 'ambiguous case' where there are two possible triangles or no triangle at all. Leave side a or side b empty and fill in the other two sides and angle C: when two triangles fit, the calculator shows both values of the missing side; when none fits, it says so.

### What units should I use for angles?

You can use either degrees (default) or radians for angle C. The calculator will convert between them automatically. Angles A and B are shown in degrees. Degrees are more common for most applications.

### What additional properties does the calculator provide?

Besides the sides and angles, the calculator provides the triangle's perimeter, area (using Heron's formula), inradius, and circumradius.
