Method Deck / geometry

Triangle area by Heron's formula

Computes the area of a triangle from its three side lengths using Heron's formula.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Compute the semiperimeter s = (a + b + c) / 2.
  2. Check the triangle inequality: s*(s-a)*(s-b)*(s-c) must be positive, otherwise the three lengths cannot form a triangle.
  3. area = sqrt( s*(s-a)*(s-b)*(s-c) ).
  4. Round to 2 decimals.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"a":3,"b":4,"c":5}6.00
test vector: isosceles triangle{"a":5,"b":5,"c":6}12.00

Published card