# Integer coordinate set of points that is a member of sphere surface

I have a graphic application to develop which involve many spheres. I should determine then on run time.

Supposing that I have a sphere of radius r, how can I determine the sub set of the sphere surface points that are integer?

E.g., $r = 10$ I can have $(10,0,0), (8,6,0),$ etc.

(Obs.: I really think this is not a programming question, that's why I not posted In stack overflow. If I am wrong, please fell free to warn me that :)

Pedro

• You could just check the integer "grid" the sphere is in by using the formula of the sphere to see which points are on the surface of the sphere. – Listing Dec 6 '11 at 9:59
• Ok, thats a alternative. But it results in a solution O(n³), which I am trying to avoid... – Pedro Dusso Dec 6 '11 at 10:17
• Have you seen this? – J. M. is a poor mathematician Dec 6 '11 at 10:30
• Obviously, there are no solutions if $r^2$ is not an integer. Are you assuming that $r$ is an integer? – Gerry Myerson Dec 6 '11 at 11:54
• – Will Jagy Dec 8 '11 at 19:48

## 1 Answer

You could use Euclid's formula: For $m > n, a = m^2 - n^2, b = 2mn, c = m^2 + n^2$ are solutions to $a^2 + b^2 = c^2$.

• The question's about spheres, not circles. – J. M. is a poor mathematician Dec 8 '11 at 18:11
• And then there is the Gauss-Legendre theorem that an integer is the sum of three integer squares if and only if it is not of the form $4^m(8n+7)$. – marty cohen Apr 7 '12 at 4:34