Law of cosines calculator and triangle solver
Choose what you know and type the numbers. Every side and angle, drawn to scale, with the working; SSA shows both triangles when there are two.
Which law the solver uses
The case you choose decides the route[1]:
- SSS (three sides) and SAS (two sides and the angle between them): the law of cosines, which needs no angle opposite a known side.
- ASA and AAS (two angles and a side): the third angle is 180° minus the other two, then the law of sines.
- SSA (two sides and an angle that is not between them): the law of sines, which can give no triangle, one or two. The solver draws every triangle that fits.
Side a is opposite angle A, and so on; R is the radius of the circle through the three corners. When C = 90°, cos C = 0 and the law of cosines is Pythagoras’s theorem.
Two triangles from one set of numbers
With angle A = 30°, b = 10 and a = 7, the height from the far corner is h = b sin A = 5. Side a is longer than h but shorter than b, so it reaches the base in two places: B ≈ 45.58° or B ≈ 134.42°, and c ≈ 13.56 or 3.76. Both are correct answers to the question as asked. Choose SSA in the solver to see them side by side.
A worked example (SAS)
Sides b = 5 and c = 7 with the angle A = 60° between them. The law of cosines gives a² = 25 + 49 − 2 × 5 × 7 × cos 60° = 74 − 35 = 39, so a = √39 ≈ 6.245. The other angles follow from the law of cosines again: B ≈ 43.90° and C ≈ 76.10°, and the three angles add to 180°.
Inputs, precision and limits
Angles are in degrees, between 0° and 180°, and decimals are kept. Sides must be positive and in the same unit, between a billionth and a billion units; outside that range the box says so and asks you to change the unit. (The angles depend only on the shape, so the solver works on the triangle scaled to a longest side of 1.) If the numbers cannot make a triangle (sides that break the triangle inequality, or two angles that already add to 180° or more), the solver says why instead of drawing something. Results are shown to two or three decimal places. Angles from three sides use Kahan’s numerically stable formula, so even a long thin “needle” triangle gets a positive smallest angle[2]. The triangles are flat; triangles drawn on a sphere follow different laws.
Sources
- (2021). Precalculus 2e (§5.1 Angles, §5.2 Unit circle, §5.3 The other trigonometric functions, §6.1–6.2 Graphs, §6.3 Inverse trigonometric functions, §7.2–7.3 Identities, §8.1–8.2 Non-right triangles, §8.3–8.4 Polar coordinates). OpenStax, Rice University. textbook
- (2014). Miscalculating Area and Angles of a Needle-like Triangle (lecture notes, §1–5 and Table 1). University of California, Berkeley. primary