Finding a Face Diagonal

Introduction

Welcome back to Real-World and 3D Applications! We have reached lesson six of seven, so the finish line is in sight. Last time, we stepped inside a rectangular box and mapped out the two types of diagonals hidden within it — face diagonals that lie flat on a single face and space diagonals that cut through the interior. We also traced the two connected right triangles that link those diagonals together. Today, we pick up where that spatial picture left off and start computing. Our target is the face diagonal: the straight-line distance from one corner of a rectangular face to the opposite corner.

The Face Diagonal Is a 2D Problem

Here is some encouraging news: computing a face diagonal does not require any new math. A face diagonal lies entirely on one rectangular face of the box. That face is simply a rectangle, and its diagonal splits it into two right triangles. The two edges bordering that face serve as the legs, and the diagonal is the hypotenuse.

Rectangle face with sides a and b and diagonal d_f

This is the same flat-rectangle setup we used in Lesson 4 when we found screen diagonals and walking shortcuts. The only thing that changes is the context — instead of a standalone rectangle, the rectangle is now one face of a three-dimensional box. The calculation itself is identical.

The Step-by-Step Procedure

Suppose a rectangular face has edge lengths aa and bb. The face diagonal dfd_f is the hypotenuse of a right triangle with legs aa and bb, so by the Pythagorean theorem:

df=a2+b2d_f = \sqrt{a^2 + b^2}

The process breaks into three quick steps:

  1. Square each edge length.
  2. Add the two squares.
  3. Take the square root of the sum.

Let's try this with a bottom face measuring 99 by 1212. We square each edge: 92=819^2 = 81 and 122=14412^2 = 144. We add: 81+144=22581 + 144 = 225. We take the square root: 225=15\sqrt{225} = 15. The face diagonal is 15 units long.

If you recognize 9-12-159\text{-}12\text{-}15 as the 3-4-5 Pythagorean triple scaled by 33, that is a great shortcut straight from Lesson 2!

When the Answer Is Not a Whole Number

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal