Project Nayuki


Triangle solver (JavaScript)

Triangle diagram with sides and angles labelled
Variable Input Solution Solution 2
Area (square units):
Status:

Description

When you give exactly three pieces of information, including at least one side, this JavaScript program calculates the missing sides and angles of a triangle.

Math notes:

  • All sides are measured in the same unit. For example, you cannot directly solve a triangle with the sides 3 metres, 5 feet, and 2 yards; you must convert the side lengths to a common unit first.

  • In a valid solution, all side lengths are positive, and all angles are greater than 0° and less than 180°.

  • Two sides and one enclosed angle (SAS) always yields one unique solution.

  • Two angles and one side (ASA, AAS) yields one unique solution, provided that the two given angles add up to less than 180°.

  • Three sides (SSS) yields one unique solution, provided that the longest side is longer than the sum of the other sides.

  • Two sides and one non-enclosed angle (SSA) yields zero, one, or two solutions.

Miscellaneous notes:

Download

A standalone offline version is available for download: triangle-solver.xhtml (right-click the link to save)

This file is free for personal use. For teachers or commercial use, please contact me to buy a registration for $10 USD.

More info