Logo for Nemo Nisi Mors
Random Quote
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
Martin Golding
Modified 2019-02-16T11:48:56Z

What is the relation between the length of the space diagonal $$a$$ and the lengths of the edges $$x$$, $$y$$ and $$z$$ in a three-dimensional box?

Figure 1: Space diagonal $$a$$ in a box with sides $$x$$, $$y$$ and $$z$$.

If we draw the face diagonal $$b$$ for the rectangle defined by the edges $$x$$ and $$y$$, we can see that we have a right triangle (blue below) with the sides $$x$$, $$y$$ and the hypotenuse $$b$$.

Figure 2: Space diagonal $$a$$ and face diagonal $$b$$ in a box, where $$b^2 = x^2 + y^2$$.

Now we can see that the space diagonal $$a$$ is the hypotenuse of a right triangle (red below), with the sides $$b$$ and $$z$$.

Figure 3: Space diagonal $$a$$ and face diagonal $$b$$ in a box, where $$a^2 = b^2 + z^2$$.

Thanks to Pythagoras, we have these relations between the variables

b^2 = x^2 + y^2
a^2 = b^2 + z^2 = x^2 + y^2 + z^2
a = \sqrt{x^2 + y^2 + z^2}

So the length of the space diagonal in a box is expressed by a simple equation between the length of the three edges.

# Diagonal in a cube

In the special case of a cube all edges are equal ($$x$$ = $$y$$ = $$z$$)

a^2 = x^2 + x^2 + x^2 = 3x^2
a = \sqrt{3x^2} = x\sqrt{3}

Note: If you want to bring your 165 cm skis when traveling, but the maximum package dimension for a side is 100 cm, you can solve your problem by putting the skis in a 100x100x100 cm box.

# Diagonal in a square

We leave the three-dimensional geometry and examine the two-dimension instead. For a square with edges of length $$x$$, the face diagonal $$b$$ is

b^2 = x^2 + x^2 = 2x^2
b = \sqrt{2x^2} = x\sqrt{2}

# Diagonal in a line

Now to the one-dimension. For a line of length $$x$$, the "diagonal" $$c$$ can be expressed as

c^2 = x^2 = 1x^2
c = \sqrt{1x^2} = x\sqrt{1}

Note: The length of the "diagonal" of a line is of course equal to the length of the line itself, but we want to follow the pattern from the previous equations.

# Diagonal in an n-dimensional hypercube

It seems to be so nice, that for the $$n$$-dimensional hypercube with edges of length $$x$$, the diagonal $$d$$ is calculated by

d = x\sqrt{n}