{
  "id": "diagonal",
  "version": "8dee7c216206",
  "status": "published",
  "name": "Diagonal Calculator",
  "question": "What is the diagonal length?",
  "summary": "Computes the diagonal of a rectangle, square, box (rectangular prism) or cube from its sides, or the missing side of a rectangle from its diagonal, with the exact root.",
  "category": "math",
  "subcategory": "geometry",
  "url": "https://www.acalculator.org/math/diagonal-calculator",
  "markdown": "https://www.acalculator.org/math/diagonal-calculator.md",
  "kind": "function",
  "method": "Rectangle: d = √(l² + w²); square: d = s√2; box: d = √(l² + w² + h²); cube: d = s√3; missing side: w = √(d² − l²).",
  "assumptions": [
    "Every size is in the same unit, from 0.000000001 to 1,000,000,000.",
    "Rectangles and boxes have right angles at every corner.",
    "For a missing side, the diagonal must be longer than the side you know."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "shape": {
        "title": "Shape",
        "description": "The shape whose diagonal you want, or a rectangle’s missing side from its diagonal.",
        "type": "string",
        "enum": [
          "rectangle",
          "square",
          "box",
          "cube",
          "side"
        ]
      },
      "l": {
        "title": "Length (l)",
        "description": "The length of the rectangle or box, or the side you know.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000
      },
      "w": {
        "title": "Width (w)",
        "description": "The width of the rectangle or box.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000
      },
      "h": {
        "title": "Height (h)",
        "description": "The height of the box.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000
      },
      "s": {
        "title": "Side (s)",
        "description": "The side of the square or cube.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000
      },
      "d": {
        "title": "Diagonal (d)",
        "description": "The diagonal of the rectangle, longer than the side you know.",
        "type": "number",
        "minimum": 1e-9,
        "maximum": 1000000000
      },
      "u": {
        "title": "Unit",
        "description": "The unit of the sizes you type; the answer is in the same unit.",
        "type": "string",
        "enum": [
          "none",
          "in",
          "ft",
          "yd",
          "mm",
          "cm",
          "m"
        ]
      }
    }
  },
  "outputs": {
    "d": {
      "label": "Diagonal",
      "description": "The diagonal (or, for a missing side, the other side), in the unit of the sides.",
      "format": "number"
    },
    "exact": {
      "label": "Exact value",
      "description": "The answer as a simplified square root of the exact fraction, such as 5√2.",
      "format": "text"
    },
    "squared": {
      "label": "Square of the answer",
      "description": "The sum (or difference) of the squares under the root, before the square root.",
      "format": "number"
    },
    "angle": {
      "label": "Angle with the length (°)",
      "description": "For a rectangle or square, the angle in degrees between the diagonal and the length side.",
      "format": "number"
    },
    "what": {
      "label": "Answer is",
      "description": "What the answer measures: the diagonal, or the other side.",
      "format": "text"
    },
    "shown": {
      "label": "Answer with unit",
      "description": "The answer to 10 significant figures, with the unit you chose.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "shape": "rectangle",
      "l": 4,
      "w": 3,
      "h": 12,
      "s": 1,
      "d": 5,
      "u": "none"
    },
    "outputs": {
      "d": 5,
      "exact": "5",
      "squared": 25,
      "angle": 36.86989764584402,
      "what": "diagonal",
      "shown": "5"
    },
    "text": "The diagonal is 5."
  },
  "examples": [
    {
      "given": {
        "shape": "rectangle",
        "l": 4,
        "w": 3,
        "u": "none"
      },
      "expect": {
        "d": 5,
        "squared": 25,
        "exact": "5",
        "angle": 36.86989764584402
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.1 The Rectangular Coordinate Systems and Graphs (distance formula, from the Pythagorean theorem). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs; hand calculation in content.mdx: √(4² + 3²) = √25 = 5"
    },
    {
      "given": {
        "shape": "square",
        "s": 5,
        "u": "cm"
      },
      "expect": {
        "d": 7.0710678118654755,
        "exact": "5√2 cm",
        "angle": 45
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.1 The Rectangular Coordinate Systems and Graphs (distance formula, from the Pythagorean theorem). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs; hand calculation in content.mdx: √(25 + 25) = √50 = 5√2"
    },
    {
      "given": {
        "shape": "box",
        "l": 4,
        "w": 3,
        "h": 12,
        "u": "none"
      },
      "expect": {
        "d": 13,
        "squared": 169,
        "exact": "13"
      },
      "source": "OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions (distance between two points in space). https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions; hand calculation in content.mdx: √(16 + 9 + 144) = √169 = 13"
    },
    {
      "given": {
        "shape": "cube",
        "s": 2,
        "u": "ft"
      },
      "expect": {
        "d": 3.4641016151377544,
        "exact": "2√3 ft"
      },
      "source": "OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions (distance between two points in space). https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions; hand calculation in content.mdx: √(3 × 4) = √12 = 2√3"
    },
    {
      "given": {
        "shape": "side",
        "l": 48,
        "d": 55,
        "u": "in"
      },
      "expect": {
        "d": 26.851443164195103,
        "squared": 721,
        "exact": "√721 in"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.1 The Rectangular Coordinate Systems and Graphs (distance formula, from the Pythagorean theorem). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs; hand calculation in content.mdx: √(55² − 48²) = √(3025 − 2304) = √721"
    },
    {
      "given": {
        "shape": "rectangle",
        "l": 1.5,
        "w": 2,
        "u": "none"
      },
      "expect": {
        "d": 2.5,
        "exact": "5/2"
      },
      "source": "OpenStax, Algebra and Trigonometry 2e, §2.1 The Rectangular Coordinate Systems and Graphs (distance formula, from the Pythagorean theorem). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs; hand calculation in content.mdx: √(2.25 + 4) = √6.25 = 2.5"
    }
  ],
  "sources": [
    "OpenStax, Algebra and Trigonometry 2e, §2.1 The Rectangular Coordinate Systems and Graphs (the distance formula, from the Pythagorean theorem). https://openstax.org/books/algebra-and-trigonometry-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs (retrieved 2026-10-02)",
    "OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions (the distance between two points in space, √(Δx² + Δy² + Δz²)). https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions (retrieved 2026-10-02)"
  ],
  "related": [
    "pythagorean-theorem",
    "right-triangle",
    "aspect-ratio",
    "distance-formula"
  ],
  "changelog": []
}
