{
  "id": "triangle",
  "version": "1bf305e4838a",
  "status": "published",
  "name": "Triangle Calculator",
  "question": "How do I solve my triangle?",
  "summary": "Solves any triangle from three of its sides and angles (SSS, SAS, ASA, AAS, or SSA with both triangles): the other sides and angles, area, perimeter, heights, medians, and radii.",
  "category": "math",
  "subcategory": "geometry",
  "url": "https://www.acalculator.org/math/triangle-calculator",
  "markdown": "https://www.acalculator.org/math/triangle-calculator.md",
  "kind": "function",
  "method": "Law of cosines a² = b² + c² − 2bc cos A and law of sines a ÷ sin A = b ÷ sin B = c ÷ sin C, with A + B + C = 180°.",
  "assumptions": [
    "Exactly three of the six values are typed, and at least one is a side.",
    "Sides are positive numbers in any one unit; angles are more than 0° and less than 180°, in degrees or radians.",
    "Two sides and an angle not between them can fit two triangles (the ambiguous case): values that differ show as a pair.",
    "Angles and areas come from the typed values in stable forms (Kahan), so needle-like triangles keep their accuracy."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "known": {
        "title": "What do you know?",
        "description": "Which three parts of the triangle you know.",
        "type": "string",
        "enum": [
          "sss",
          "sas",
          "asa",
          "aas",
          "ssa"
        ]
      },
      "a": {
        "title": "Side a",
        "description": "The length of side a, opposite angle A.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "b": {
        "title": "Side b",
        "description": "The length of side b, opposite angle B.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "c": {
        "title": "Side c",
        "description": "The length of side c, opposite angle C.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "A": {
        "title": "Angle A",
        "description": "The angle A, between sides b and c, opposite side a.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "angle",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 3.141592653589793
      },
      "B": {
        "title": "Angle B",
        "description": "The angle B, between sides a and c, opposite side b.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "angle",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 3.141592653589793
      },
      "C": {
        "title": "Angle C",
        "description": "The angle C, between sides a and b, opposite side c.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "angle",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 3.141592653589793
      }
    }
  },
  "outputs": {
    "sideA": {
      "label": "Side a",
      "description": "The length of side a, opposite angle A.",
      "format": "number"
    },
    "sideB": {
      "label": "Side b",
      "description": "The length of side b, opposite angle B.",
      "format": "number"
    },
    "sideC": {
      "label": "Side c",
      "description": "The length of side c, opposite angle C.",
      "format": "number"
    },
    "angleA": {
      "label": "Angle A",
      "description": "The angle opposite side a.",
      "format": "quantity",
      "unit": "deg"
    },
    "angleB": {
      "label": "Angle B",
      "description": "The angle opposite side b.",
      "format": "quantity",
      "unit": "deg"
    },
    "angleC": {
      "label": "Angle C",
      "description": "The angle opposite side c.",
      "format": "quantity",
      "unit": "deg"
    },
    "area": {
      "label": "Area",
      "description": "The area inside the triangle, in square units.",
      "format": "number"
    },
    "perimeter": {
      "label": "Perimeter",
      "description": "The sum of the three sides.",
      "format": "number"
    },
    "heightA": {
      "label": "Height to side a",
      "description": "The distance from vertex A to the line through side a: 2 × area ÷ a.",
      "format": "number"
    },
    "heightB": {
      "label": "Height to side b",
      "description": "The distance from vertex B to the line through side b: 2 × area ÷ b.",
      "format": "number"
    },
    "heightC": {
      "label": "Height to side c",
      "description": "The distance from vertex C to the line through side c: 2 × area ÷ c.",
      "format": "number"
    },
    "medianA": {
      "label": "Median to side a",
      "description": "The line from vertex A to the middle of side a.",
      "format": "number"
    },
    "medianB": {
      "label": "Median to side b",
      "description": "The line from vertex B to the middle of side b.",
      "format": "number"
    },
    "medianC": {
      "label": "Median to side c",
      "description": "The line from vertex C to the middle of side c.",
      "format": "number"
    },
    "inradius": {
      "label": "Inradius",
      "description": "The radius of the largest circle inside the triangle: area ÷ half the perimeter.",
      "format": "number"
    },
    "circumradius": {
      "label": "Circumradius",
      "description": "The radius of the circle through the three corners: a ÷ (2 sin A).",
      "format": "number"
    },
    "type": {
      "label": "Type of triangle",
      "description": "Acute, right, or obtuse by its largest angle; equilateral, isosceles, or scalene by its sides.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "known": "sss",
      "a": 5,
      "b": 6,
      "c": 7,
      "A": 0.7853981633974483,
      "B": 1.0471975511965976,
      "C": 0.8726646259971648
    },
    "outputs": {
      "sideA": 5,
      "sideB": 6,
      "sideC": 7,
      "angleA": 0.7751933733103613,
      "angleB": 0.9969608742748661,
      "angleC": 1.369438406004566,
      "area": 14.696938456699069,
      "perimeter": 18,
      "heightA": 5.878775382679628,
      "heightB": 4.898979485566357,
      "heightC": 4.199125273342591,
      "medianA": 6.020797289396148,
      "medianB": 5.291502622129181,
      "medianC": 4.272001872658766,
      "inradius": 1.632993161855452,
      "circumradius": 3.5721725415588015,
      "type": "Acute scalene"
    },
    "text": "A triangle with sides 5, 6, and 7 has angles 44.415309°, 57.12165°, and 78.463041°, and an area of 14.696938."
  },
  "examples": [
    {
      "given": {
        "known": "sss",
        "a": 5,
        "b": 6,
        "c": 7
      },
      "expect": {
        "angleA": 0.7751933733103613,
        "angleB": 0.9969608742748661,
        "angleC": 1.369438406004566,
        "area": 14.696938456699069,
        "perimeter": 18,
        "inradius": 1.632993161855452,
        "circumradius": 3.5721725415588015,
        "heightC": 4.199125273342591,
        "medianC": 4.272001872658765,
        "type": "Acute scalene"
      },
      "source": "hand calculation in content.mdx: cos A = (36 + 49 − 25) ÷ 84; Heron with s = 9: √(9 × 4 × 3 × 2) = 6√6; Python 3 (progress log)"
    },
    {
      "given": {
        "known": "sas",
        "a": 3,
        "b": 4,
        "C": 1.5707963267948966
      },
      "expect": {
        "sideC": 5,
        "angleA": 0.6435011087932844,
        "area": 6,
        "circumradius": 2.5,
        "type": "Right scalene"
      },
      "source": "hand calculation in content.mdx: SAS, c² = 9 + 16 − 0 = 25; A = atan(3/4)"
    },
    {
      "given": {
        "known": "asa",
        "A": 0.5235987755982988,
        "B": 0.7853981633974483,
        "c": 10
      },
      "expect": {
        "angleC": 1.8325957145940461,
        "sideA": 5.176380902050416,
        "sideB": 7.320508075688773,
        "area": 18.30127018922193,
        "type": "Obtuse scalene"
      },
      "source": "hand calculation in content.mdx: ASA, C = 180° − 30° − 45° = 105°, a = 10 sin 30° ÷ sin 105°; Python 3 (progress log)"
    },
    {
      "given": {
        "known": "aas",
        "A": 0.5235987755982988,
        "B": 0.7853981633974483,
        "a": 10
      },
      "expect": {
        "sideB": 14.142135623730951,
        "sideC": 19.318516525781366,
        "angleC": 1.8325957145940461
      },
      "source": "hand calculation in content.mdx: AAS, C = 105°, b = 10 sin 45° ÷ sin 30° = 10√2, c = 10 sin 105° ÷ sin 30°; mpmath (progress log)"
    },
    {
      "given": {
        "known": "ssa",
        "a": 6,
        "b": 8,
        "A": 0.5235987755982988
      },
      "expect": {
        "sideC": 11.400339185275088
      },
      "source": "hand calculation in content.mdx: SSA, c² − 8√3 c + 28 = 0, so c = 4√3 ± √20 = 11.400339 or 2.456067; mpmath (progress log)"
    },
    {
      "given": {
        "known": "sss",
        "a": 10,
        "b": 10,
        "c": 10
      },
      "expect": {
        "angleA": 1.0471975511965979,
        "area": 43.30127018922193,
        "type": "Acute equilateral"
      },
      "source": "hand calculation in content.mdx: equilateral, every angle 60°, area = √3 ÷ 4 × 100"
    },
    {
      "given": {
        "known": "sss",
        "a": 100000,
        "b": 99999.99999,
        "c": 0.00002
      },
      "expect": {
        "angleC": 1.732050612201726e-10,
        "area": 0.8660253060142605
      },
      "source": "needle triangle (Kahan 2014): mpmath at 100 digits on the float inputs, C from the law of cosines, area by Heron (progress log)"
    }
  ],
  "sources": [
    "OpenStax, Algebra and Trigonometry 2e, §10.1 Non-right Triangles: Law of Sines and §10.2 Non-right Triangles: Law of Cosines (the ambiguous case, Heron’s formula). https://openstax.org/books/algebra-and-trigonometry-2e/pages/10-1-non-right-triangles-law-of-sines",
    "W. Kahan, \"Miscalculating Area and Angles of a Needle-like Triangle\" (2014), for the stable forms of the area and the angles. https://people.eecs.berkeley.edu/~wkahan/Triangle.pdf",
    "Weisstein, Eric W. \"Triangle Median\", MathWorld (m_a = ½√(2b² + 2c² − a²)). https://mathworld.wolfram.com/TriangleMedian.html"
  ],
  "related": [
    "right-triangle",
    "triangle-area",
    "law-of-cosines",
    "pythagorean-theorem",
    "trigonometry"
  ],
  "changelog": []
}
