Finding a Space Diagonal

Introduction

Welcome back to Real-World and 3D Applications! You have arrived at the seventh and final lesson of the course — congratulations on making it all the way here. In Lesson 6, we computed the face diagonal across a single rectangular face of a box. Today, we take one more step into the interior of the box itself. Our goal is to find the space diagonal: the longest possible straight line inside a rectangular box, stretching from one corner all the way to the opposite corner. By the end of this lesson, you will be able to calculate that distance by applying the Pythagorean theorem twice in sequence.

From Face Diagonal to Space Diagonal

Recall from Lesson 5 that every rectangular box contains two connected right triangles linking its edges to the space diagonal. The first right triangle lies flat on the base, where two edges serve as legs and the face diagonal is the hypotenuse. The second right triangle stands upright inside the box, using that same face diagonal as one leg and the box's height as the other, with the space diagonal as its hypotenuse.

The diagram below shows the two linked right triangles inside a rectangular box.

Labeled rectangular prism showing length, width, height, face diagonal, and space diagonal

This means finding a space diagonal is really just the Pythagorean theorem applied twice in a row. We already mastered the first application in Lesson 6. Today, we add the second.

The Two-Step Procedure

Let a rectangular box have length ll, width ww, and height hh. We find the space diagonal dsd_s by working through two right triangles in sequence.

Step 1 — Find the face diagonal. Choose the base (or any convenient face). Its diagonal dfd_f satisfies:

df2=l2+w2d_f^2 = l^2 + w^2

Step 2 — Find the space diagonal. The face diagonal dfd_f and the remaining edge hh form the legs of a second right triangle whose hypotenuse is dsd_s:

ds2=df2+h2d_s^2 = d_f^2 + h^2

Since df2=l2+w2d_f^2 = l^2 + w^2, we can substitute directly:

ds2=l2+w2+h2d_s^2 = l^2 + w^2 + h^2

Taking the square root gives us a compact formula:

ds=l2+w2+h2d_s = \sqrt{l^2 + w^2 + h^2}

Notice the elegant result: the space diagonal equals the square root of the sum of all three squared edge lengths. Even though two separate right triangles are involved, everything collapses into one tidy expression.

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