{
  "id": "law-of-cosines",
  "version": "c66e1bfc6c55",
  "status": "published",
  "name": "Law of Cosines Calculator",
  "question": "How do I use the law of cosines?",
  "summary": "Finds the third side of a triangle from two sides and the angle between them, an angle from three sides, or a side from two sides and an angle.",
  "category": "math",
  "subcategory": "geometry",
  "url": "https://www.acalculator.org/math/law-of-cosines-calculator",
  "markdown": "https://www.acalculator.org/math/law-of-cosines-calculator.md",
  "kind": "formulas",
  "method": "c² = a² + b² − 2ab cos C, where C is the angle between sides a and b.",
  "assumptions": [
    "Angles are between 0° and 180°; sides are more than 0, in any one unit.",
    "Two sides and the angle opposite one of them can fit two triangles (the ambiguous case): both answers are shown.",
    "Three sides must satisfy the triangle inequality: each side shorter than the other two together.",
    "Angles A and B, the area, and the radii come from the three typed values in stable forms (Kahan), so needle-like triangles keep their accuracy; the circumradius c ÷ (2 sin C) shows once in the ambiguous case."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "sideA": {
        "title": "Side a",
        "description": "The length of side a, opposite angle A.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "sideB": {
        "title": "Side b",
        "description": "The length of side b, opposite angle B.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "sideC": {
        "title": "Side c",
        "description": "The length of side c, opposite angle C.",
        "type": "number",
        "exclusiveMinimum": 0
      },
      "angle": {
        "title": "Angle C",
        "description": "The angle between sides a and b, opposite side c.",
        "type": [
          "number",
          "string"
        ],
        "x-quantity": "angle",
        "exclusiveMinimum": 0,
        "exclusiveMaximum": 3.141592653589793
      }
    }
  },
  "solve": {
    "fillAny": 3,
    "variables": [
      "sideA",
      "sideB",
      "sideC",
      "angle"
    ],
    "inputsOnly": []
  },
  "outputs": {
    "a": {
      "label": "Side a",
      "description": "The length of side a, opposite angle A.",
      "format": "number"
    },
    "b": {
      "label": "Side b",
      "description": "The length of side b, opposite angle B.",
      "format": "number"
    },
    "c": {
      "label": "Side c",
      "description": "The length of side c, opposite angle C.",
      "format": "number"
    },
    "C": {
      "label": "Angle C",
      "description": "The angle between sides a and b, opposite side c.",
      "format": "quantity"
    },
    "A": {
      "label": "Angle A",
      "description": "The angle opposite side a.",
      "format": "quantity",
      "unit": "deg"
    },
    "B": {
      "label": "Angle B",
      "description": "The angle opposite side b.",
      "format": "quantity",
      "unit": "deg"
    },
    "perimeter": {
      "label": "Perimeter",
      "description": "The sum of the three sides: a + b + c.",
      "format": "number"
    },
    "area": {
      "label": "Area",
      "description": "The area of the triangle, from Heron’s formula.",
      "format": "number"
    },
    "inradius": {
      "label": "Inradius",
      "description": "The radius of the inscribed circle: area ÷ half the perimeter.",
      "format": "number"
    },
    "circumradius": {
      "label": "Circumradius",
      "description": "The radius of the circumscribed circle: abc ÷ (4 × area).",
      "format": "number"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "sideA": 5,
      "sideB": 7,
      "angle": 1.0471975511965976
    },
    "outputs": {
      "c": 6.244997998398397,
      "A": 0.7661626496937841,
      "B": 1.3282324526994114,
      "perimeter": 18.244997998398397,
      "area": 15.155444566227676,
      "inradius": 1.66132597740576,
      "circumradius": 3.605551275463989
    },
    "text": "A triangle with sides 5 and 7 and the angle 60° between them has a third side of 6.244998."
  },
  "examples": [
    {
      "given": {
        "sideA": 5,
        "sideB": 7,
        "angle": 1.0471975511965976
      },
      "expect": {
        "sideC": 6.244997998398398,
        "perimeter": 18.244997998398397,
        "area": 15.155444566227676
      },
      "source": "hand calculation in content.mdx: c² = 25 + 49 − 2 × 5 × 7 × 0.5 = 39; area = ½ × 5 × 7 × sin 60°"
    },
    {
      "given": {
        "sideA": 3,
        "sideB": 4,
        "angle": 1.5707963267948966
      },
      "expect": {
        "sideC": 5,
        "A": 0.6435011087932844,
        "area": 6,
        "inradius": 1,
        "circumradius": 2.5
      },
      "source": "hand calculation in content.mdx: 3-4-5 right triangle; A = asin(3/5); Python 3: math.asin(0.6) = 0.6435011087932844"
    },
    {
      "given": {
        "sideA": 5,
        "sideB": 7,
        "sideC": 8
      },
      "expect": {
        "angle": 1.4274487578895312,
        "B": 1.0471975511965976,
        "area": 17.320508075688775
      },
      "source": "hand calculation in content.mdx: cos C = (25 + 49 − 64) ÷ 70 = 1/7; cos B = (25 + 64 − 49) ÷ 80 = 1/2"
    },
    {
      "given": {
        "sideB": 8,
        "sideC": 7,
        "angle": 1.0471975511965976
      },
      "expect": {
        "sideA": 5
      },
      "source": "hand calculation in content.mdx: a² − 8a + 15 = 0, so a = 5 or 3"
    },
    {
      "given": {
        "sideA": 5,
        "sideB": 7,
        "angle": 2
      },
      "expect": {
        "sideC": 10.155307900713792
      },
      "source": "hand calculation in content.mdx: c² = 74 − 70 cos 2 rad; Python 3: math.sqrt(74 - 70 * math.cos(2)) = 10.155307900713792"
    },
    {
      "given": {
        "sideB": 0.023706805114632263,
        "sideC": 8286.471047868416,
        "angle": 0.039593057849782246
      },
      "expect": {
        "B": 1.1324237870817625e-7,
        "circumradius": 104672.85032807532
      },
      "source": "needle triangle (SSA) from docs/progress/WP-60-24.md, finding 1; mpmath at 256 bits: sin B = b sin C ÷ c, R = c ÷ (2 sin C)"
    },
    {
      "given": {
        "sideA": 0.001,
        "sideB": 1000,
        "angle": 0.001
      },
      "expect": {
        "A": 1.000000833333675e-9,
        "area": 0.0004999999166666708,
        "circumradius": 499999.5833335097
      },
      "source": "needle triangle (SAS) from docs/progress/WP-60-24.md, finding 1; mpmath at 256 bits: A = atan2(a sin C, b − a cos C)"
    }
  ],
  "sources": [],
  "related": [],
  "changelog": [
    {
      "date": "2026-09-28",
      "note": "Three sides that make no triangle name the rule."
    }
  ]
}
