acalculator

What is the diagonal length?

Pick a shape and type its sides. The diagonal calculator shows the diagonal as a decimal and as an exact square root, such as 5√2.

Your numbers

Shape
Unit
Diagonal
5

The diagonal is 5.

Exact value
5
Square of the answer
25
Angle with the length (°)
36.8699
Answer is
diagonal
Answer with unit
5

Diagonal: 5. The diagonal is 5.

How to calculate

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.

Example with the default inputs (Shape Rectangle, Length (l) 4, Width (w) 3, Unit None): The diagonal is 5.

Method: Rectangle: d = √(l² + w²); square: d = s√2; box: d = √(l² + w² + h²); cube: d = s√3; missing side: w = √(d² − l²).

  • 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.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Shape Rectangle, Length (l) 4, Width (w) 3, Unit None gives Diagonal 5, Square of the answer 25, Exact value 5, Angle with the length (°) 36.869898.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
  2. Shape Square, Side (s) 5, Unit cm gives Diagonal 7.071068, Exact value 5√2 cm, Angle with the length (°) 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
  3. Shape Box, Length (l) 4, Width (w) 3, Height (h) 12, Unit None gives Diagonal 13, Square of the answer 169, Exact value 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
  4. Shape Cube, Side (s) 2, Unit ft gives Diagonal 3.464102, Exact value 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
  5. Shape Missing side, Length (l) 48, Diagonal (d) 55, Unit in gives Diagonal 26.851443, Square of the answer 721, Exact value √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
  6. Shape Rectangle, Length (l) 1.5, Width (w) 2, Unit None gives Diagonal 2.5, Exact value 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

How it works

The diagonal joins two opposite corners, so it is the distance between them (the distance formula, from the Pythagorean theorem):

  • Rectangle l × w: d = √(l² + w²)
  • Square with side s: d = √(s² + s²) = s√2
  • Box (rectangular prism) l × w × h, corner to opposite corner: d = √(l² + w² + h²)
  • Cube with side s: d = √(3s²) = s√3
  • Missing side of a rectangle from its diagonal d and one side l: w = √(d² − l²). The diagonal must be longer than l; otherwise there is no answer.
  • Angle with the length (rectangle and square): arctan(w ÷ l) in degrees.

Exact value. Each size is read as the exact decimal you typed, so the number under the root (d²) is an exact fraction N/D in lowest terms, and √(N/D) = √(N × D) ÷ D. The square part of M = N × D is found by trial division: for p = 2, 3, 5, 7, 9, … (2, then every odd number) while p ≤ 10,000 and p² ≤ what is left of M, divide out p² as often as it goes (k gains a factor p each time), then p once if it still divides (s gains a factor p). Call what is left r. If the loop stopped because p² > r, then s gains r. Otherwise: if r < 10²⁴ and r is a perfect square t², k gains t; else if r < 10¹², s gains r; else the exact value is left out. Then k/D is put in lowest terms as k′/D′ and the root is written k′√s/D′ (no 1 before √; no /1), or k′/D′ when s = 1 (5, 5/2). With a unit chosen, the unit follows the exact value. The comparison of the diagonal with the known side is exact too.

Output format. The answer shows to 10 significant figures, the number under the root to 12, and the angle with at most 4 decimals, rounded half up. The unit only labels the answer; all sizes must be in that one unit.

Assumptions

  • Every size is from 0.000000001 to 1,000,000,000, in one unit.
  • Rectangles and boxes have right angles at every corner.

Worked examples by hand

A 4 × 3 rectangle. 4² + 3² = 16 + 9 = 25; √25 = 5. Angle: arctan(3 ÷ 4) = 36.87°.

A square with 5 cm sides. 25 + 25 = 50 = 5² × 2, so d = 5√2 cm ≈ 7.071 cm; the angle is 45°.

A 4 × 3 × 12 box. 16 + 9 + 144 = 169; √169 = 13.

A cube with 2 ft sides. 3 × 2² = 12 = 2² × 3, so d = 2√3 ft ≈ 3.464 ft.

A screen 48 in wide with a 55 in diagonal. 55² − 48² = 3,025 − 2,304 = 721 = 7 × 103, so the height is √721 in ≈ 26.85 in.

A 1.5 × 2 rectangle. 2.25 + 4 = 6.25 = 25/4; √(25/4) = 5/2 = 2.5.

Other questions people ask

How do I find the diagonal of a rectangle?

Use the Pythagorean theorem: d = √(l² + w²). A 4 × 3 rectangle has a diagonal of √(16 + 9) = √25 = 5.

What is the diagonal of a square?

A square with side s has a diagonal of s√2, about 1.414 × s. A square with 5 cm sides has a diagonal of 5√2 ≈ 7.071 cm.

How do I find the diagonal of a box?

For a box l × w × h, the space diagonal (corner to opposite corner) is √(l² + w² + h²). A 4 × 3 × 12 box has a diagonal of √169 = 13. A cube with side s has a diagonal of s√3.

How do I find a missing side from the diagonal?

Rearrange the theorem: w = √(d² − l²). A screen 48 in wide with a 55 in diagonal is √(3025 − 2304) = √721 ≈ 26.85 in high. The diagonal must be longer than the side you know.

What angle does the diagonal make with the sides?

In a rectangle the diagonal makes an angle of arctan(w ÷ l) with the length. For a 4 × 3 rectangle that is 36.87°, and for any square it is 45°.

Why does the answer show a square root?

Most diagonals are not whole numbers. The exact value keeps the square root, such as 2√3 for a cube with 2 ft sides, and the decimal shows it to 10 significant figures.