Computes the missing side of a right triangle (hypotenuse or a leg) given the other two sides.
Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.
Try it
Inputs
mode (string, required) one of: find_hypotenuse, find_leg : Which side to solve for.
known_a (number, length units, required) min 0 : For find_hypotenuse: one leg. For find_leg: the known leg.
known_b (number, length units, required) min 0 : For find_hypotenuse: the other leg. For find_leg: the hypotenuse.
Outputs
result (length units): The computed hypotenuse (find_hypotenuse) or leg (find_leg).
Steps
The Pythagorean theorem: for a right triangle with legs a and b and hypotenuse c, a^2 + b^2 = c^2.
If mode is find_hypotenuse: c = sqrt(known_a^2 + known_b^2), where known_a and known_b are the two legs.
If mode is find_leg: known_b is the hypotenuse and known_a is a leg; the missing leg = sqrt(known_b^2 - known_a^2). known_b must be greater than known_a.
Round to 2 decimals.
Constants
None.
Sources
Elements, Book I, Proposition 47 (the Pythagorean theorem) (Standard geometry reference, 2026-09-30T19:47:00Z) - Classical statement and proof of the Pythagorean theorem.