# How to show that the sum of the squares of distances from the vertices of a cube to a line passing through the center of the cube is constant?

I found a problem in Arnold's Mathematical Methods of Classical Mechanics Chapter 28 as follows:

Draw the line through the center of a cube such that the sum of the squares of its distances to the vertices of the cube is (a) largest, (b) smallest.

I found by example that the sum of squares should be a constant which is independent of the line. In the two dimensional analogue there is an easy geometric proof using Pythagorean theorem. My question is: how to prove it for a cube?

Let the origin of coordinates be the center of the cube and the $$i$$-th cube vertex be $$(e_{i1},e_{i2},e_{i3})$$ with $$e=\pm1$$. Let the direction of the line be given by the unit vector $$(x_1,x_2,x_3)$$.

Then the cosine of the angle between the line and the direction to a vertex is: $$\cos\alpha_i=\frac{e_{i1}x_1+e_{i2}x_2+e_{i3}x_3}{\sqrt3}.$$ Therefore for the sum of the squared distances from the vertices to the line one obtains: $$\sum_i 3\sin^2 \alpha_i=\sum_i 3(1-\cos^2 \alpha_i) =\sum_{i}\left[3-(e_{i1}x_1+e_{i2}x_2+e_{i3}x_3)^2\right]=16.$$ The last equality holds because all mixed terms $$x_kx_l$$ with $$k\ne l$$ cancel upon the summation.