Geometry Calculators

##### Related Content

Programmers and Teachers: Nikkolas
Tutor and Aerospace Engineer

# Law of Cosines Calculator

Solving for:
Angle unit: ## Law of Cosines Lesson

### What is the Law of Cosines?

The law of cosines is a set of formulas that relate the side lengths of a triangle with the cosines of its angles. It allows us to solve for unknown side lengths and angles of any triangle if we know two of the side lengths and one of the angles.

The three law of cosines formulas are given as:
a2 = b2 + c2 – 2bc×cos(A)
b2 = a2 + c2 – 2ac×cos(B)
c2 = a2 + b2 – 2ab×cos(C)
Where ab, and c are the side lengths and AB, and C are the angles opposite of their respective side. For example, angle A is opposite to side a and located between sides b and c

The law of cosines is a one-size-fits-all version of the Pythagorean theorem. The Pythagorean theorem has a much simpler formula but only works with right triangles. The law of cosines works with any type of triangle.

## How the Calculator Works

The calculator on this page is written in the programming language JavaScript. When you click the “calculate” button, the law of cosines function is activated. This function is run by your internet browser’s JavaScript engine which allows nearly instant answers.

At the core of the code powering this calculator are the same formulas as given above. Your inputted side lengths and angle are fed into the applicable formula, and out comes the desired side length or angle value. That resulting number is rounded to the 4th decimal place before being displayed as the answer.

The code also checks the side lengths and angles of your triangle to make sure that it follows the triangle inequality theorem and that no internal angles exceed 180 degrees. If the sides and angles do not constitute a possible triangle then no answer will be calculated.

Scroll to Top