Triangle solver (JavaScript)
Program
Tip: In the triangle diagram, click on a letter to jump to that input; hover over a letter to read its solution.
Has the triangle solver been helpful to you? Please consider liking Project Nayuki at Facebook. Thanks for your support!
Description
This JavaScript program calculates the missing sides and angles of a triangle. Give exactly 3 pieces of information, including at least one side.
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°.
3 sides (SSS) yields a unique solution, or no solution if the longest side is longer than the sum of the other sides.
2 angles and a side (ASA) always yields a unique solution, provided that the two given angles add up to less than 180°.
2 sides and an enclosed angle (SAS) always yields a unique solution.
2 sides and a non-enclosed angle (SSA) yields 0, 1, or 2 solutions.
The source code is available.