Is $(x^2+y^2+z^2)$ always a perfect square when $x=n-1, y=n, z=n(n-1)$? This question is from a non-mathematician (a programmer...) so please excuse any poor terminology.
I was writing some test data for some (X, Y, Z) coordinate to magnitude conversions.
As you know, the magnitude of a (X, Y, Z) vector is given by Pythagoras:
mag = Sqrt(X^2 + Y^2 + Z^2)

I wanted to simplify things to avoid rounding problems, so I wrote a very simple program to search for solutions for X, Y and Z where the sum of their squares was itself a perfect square.
I noticed the following solutions:
1, 2,  2
2, 3,  6
3, 4, 12
4, 5, 20
5, 6, 30
6, 7, 42

These are clearly all of the form (N-1, N, N(N-1)).
I assume this is a well-known thing, but I was unable to find any proof or discussion by googling (probably because I don't know what to search for).
Is it true that (X^2 + Y^2 + Z^2) is always a perfect square for all N where X=N-1, Y=N and Z=N(N-1)?
 A: Yes. It is easy to verify $(n^2-n+1)^2$
A: You only need to check that
$$N^2+(N-1)^2+(N(N-1))^2 = (N(N-1)+1)^2,$$
for istance. This is equivalent to:
$$ N^2+(N-1)^2 = 2N(N-1)+1$$
that is clearly true. To have all the integer solutions of $X^2+Y^2+Z^2=W^2$,
just recall that the unit sphere admits the following parametrization (in terms of Euler angles):
$$ X = \cos\theta,\quad Y=\sin\theta \cos\phi,\quad Z=\sin\theta \sin\phi, $$
then write everything in terms of $t_1=\tan\frac{\theta}{2},t_2=\tan\frac{\phi}{2}$ and you get the set of rational points on the unit sphere in terms of the two rational parameters $t_1,t_2$, i.e. all the integer solutions of $X^2+Y^2+Z^2=W^2$. Also notice that every $W^2$ can be written as a sum of three squares, since the only numbers that cannot be written in such a way are the numbers of the form $4^m(8k+7)$.
Under another perspective, to have an integer solution of $X^2+Y^2+Z^2=W^2$ you only need the possibility to write $X^2+Y^2$ as a product of two numbers with the same parity, from $X^2+Y^2=(W-Z)(W+Z)$. Every number that is not of the form $4k+2$ can be written in such a way, so you only need that $X$ and $Y$ are not both odd.
