Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :)


share|cite|improve this question
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. 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
See – Will Jagy Dec 8 '11 at 19:48

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$.

share|cite|improve this answer
The question's about spheres, not circles. – J. M. 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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.