HuntsvilleEngineers mark
HE Reference Shelf — huntsvilleengineers.com
The Reference Shelf · Geometry & Mechanics

Law of cosines

Pythagoras for triangles that don't have a right angle — one cosine term pays for the missing 90°.

Also known as: cosine rule

The formula

The main statement, for a triangle with sides a, b, c and angle γ opposite side c:

c² = a² + b² − 2·a·b·cos γ

Reading: the side across from an angle is fixed by the two sides that flank the angle and the angle itself. Set γ = 90°, the cosine is zero, and the Pythagorean theorem falls out as the special case.

Solved for an angle when all three sides are known (the SSS case):

γ = arccos( (a² + b² − c²) / (2·a·b) )

Reading: measure three lengths and you have earned every angle in the triangle — no protractor touched the part.

The force-resultant form, where θ is the angle between the two force directions, tail to tail:

R² = F₁² + F₂² + 2·F₁·F₂·cos θ

Reading: same law, plus sign. The triangle you build by walking the vectors head-to-tail has an included angle of 180° − θ, and cos(180° − θ) = −cos θ flips the sign. Two 100 N forces at θ = 0 give 200 N, not zero.

The vector form, which is what the law actually is:

|a⃗ − b⃗|² = |a⃗|² + |b⃗|² − 2·(a⃗ · b⃗)

Reading: expand the dot product of a difference with itself and the law of cosines appears. It is the dot product wearing trigonometry's clothes.

Where you meet it

  • The pull-test fixture. Two cables load a lifting lug at 60° to each other, one at 300 N and one at 500 N. The resultant is √(300² + 500² + 2·300·500·cos 60°) = √490000 = 700 N — and 700 N, not 800 N, is the number that goes against the lug's rating. Any time two actuators, cables, or thrust lines meet at an angle that isn't 90°, this is the arithmetic.
  • The tracking review. A radar sits 8 km from you, a target sits 5 km from you, and the angle between the two sightlines is 40°. The radar-to-target range is √(8² + 5² − 2·8·5·cos 40°) = 5.26 km. Two ranges and an angle to a side — that is surveying, bistatic radar geometry, and every triangulation problem on a test range.
  • The CMM report. Three tooling balls on a fixture, three measured center-to-center distances, and the SSS form hands you the as-built angles. Sides 5, 6, 7 (any units) give arccos(12/60) = 78.46° opposite the 7. Machinists have run this on trig tables since before anyone in the shop was born.
  • The structures desk. A truss drawing calls out member lengths but the field question is the angle at a gusset. Three as-built lengths in, one angle out, no assumption that anything is square — which, on as-built hardware, nothing is.

How it works

The −2·a·b·cos γ term is a projection correction. Drop a perpendicular from one vertex and the term is twice the projection of one flanking side onto the other — exactly the cross term Pythagoras never needed. When γ is acute the projection shortens c, so the term subtracts. When γ is obtuse the cosine goes negative, the subtraction becomes an addition, and c comes out longer than a right-angle triangle would allow. The formula handles both cases with one sign convention, which is precisely the improvement over doing the two cases separately.

The SSS direction is better behaved than people expect. A triangle's interior angle lives in (0°, 180°), and arccos is single-valued on exactly that interval — so unlike the law of sines, which can return two candidate angles from the same sine, the law of cosines never hands you an ambiguous answer. When you have all three sides, use cosines, not sines.

The mistakes, in the order they happen on real hardware:

  1. Wrong angle into the resultant. The angle between two force vectors is not the included angle of the head-to-tail triangle; they are supplements. Feed 60° into the minus-sign form for the two-cable example above and you get 435.9 N — a resultant smaller than one of its components, which should stop you cold. If the "resultant" is less than the larger input force and the angle between the forces was under 90°, the sign is wrong.
  2. Degrees into a radians function. cos(60) in most languages is the cosine of 60 radians, −0.952. The failure is silent and the answer is confidently wrong.
  3. arccos fed a value outside ±1. Round-off on a nearly degenerate triangle can push (a² + b² − c²)/(2ab) to 1.0000000002, and arccos returns NaN. Clamp the argument. And if the three lengths genuinely violate the triangle inequality — say 3, 4, 7, which lands exactly on −1 — the geometry is telling you the measurements are bad, not the formula.
  4. Cancellation on needle triangles. For a = b = 1000 m and γ = 0.01°, the direct form in single precision returns c = 0 exactly — a² + b² and 2ab·cos γ agree to more digits than a float32 carries. The algebraically identical, numerically stable form
c = √( (a − b)² + 4·a·b·sin²(γ/2) )

returns the correct 0.1745 m. If your code solves skinny triangles — long-baseline surveying, small-angle tracking — use the half-angle form.

Limits of validity: the law is exact for planar triangles, period. Two ranges across a county are fine; two ranges across an ocean are on a sphere, and the spherical law of cosines (cos c = cos a·cos b + sin a·sin b·cos γ, sides as central angles) takes over. And the law says nothing about triangles you haven't closed — three field measurements that don't come from the same rigid triangle will still produce an "angle," and it will mean nothing.

History

The law is older than the cosine. Around 300 BC, Euclid proved it twice in Book II of the Elements — Proposition 12 for the obtuse case, Proposition 13 for the acute — stated entirely in the language of squares and rectangles, since Greek geometry had no trigonometric functions to state it with [1][2][3]. His "twice the rectangle contained by one of the sides and the projection" is the 2·a·b·cos γ term, built from cut paper instead of a function table [2][3].

Turning that geometry into a working computation took the Persian school. Nasir al-Din al-Tusi (1201–1274) wrote the first treatise to treat trigonometry as its own branch of mathematics rather than an appendix to astronomy, laying out systematic methods for solving plane and spherical triangles [1][6]. About two centuries later Jamshid al-Kashi (c. 1380–1429) — chief computer at Ulugh Beg's observatory in Samarkand, and the man who calculated 2π to sixteen decimal places — consolidated the side-from-two-sides-and-an-angle procedure into a single usable rule in his Miftah al-Hisab (Key to Arithmetic), completed in March 1427 [1][3][4][5]. The attribution stuck: in France the result is still taught as the théorème d'Al-Kashi [1][5].

The one-line symbolic form you write today is a creature of algebraic notation, which arrived later still. François Viète (1540–1603), a lawyer and Henry IV's codebreaker who did mathematics between assignments, published methods for solving plane and spherical triangles in his Canon Mathematicus and introduced the letters-for-knowns-and-unknowns notation in 1591 that made compressing a paragraph of geometry into c² = a² + b² − 2ab·cos γ possible at all [1][7].

Related tools

  • /tools/convert-angle
  • /tools/projectile-range
  • /tools/radar-horizon
  • /tools/drag-force
  • /tools/lift-force

Sources

  1. https://en.wikipedia.org/wiki/Law_of_cosines
  2. https://mathcs.clarku.edu/~djoyce/java/elements/bookII/propII12.html
  3. https://www.theoremoftheday.org/GeometryAndTrigonometry/AlKashi/TotDAlKashi.pdf
  4. https://mathshistory.st-andrews.ac.uk/Biographies/Al-Kashi/
  5. https://en.wikipedia.org/wiki/Jamshid_al-Kashi
  6. https://mathshistory.st-andrews.ac.uk/Biographies/Al-Tusi_Nasir/
  7. https://mathshistory.st-andrews.ac.uk/Biographies/Viete/

Written by HE in our own words from the cited sources — engineering judgment included, your stamp still required. All entries →

★ The Reference Shelf

Reading is free. The shelf is for cardholders.

Your library card is an email address: pin it to your shelf, print the card, take the FE/PE quick-reference pack, read the Huntsville history. The shelf remembers what you reach for.

Already on the list? Enter with your subscribed email →