Find all vectors with magnitude between $n-\delta$ and $n+\delta$

53 Views Asked by At

I am working on an program to compute the structure factor of a given configuration of 3D points, and I need an efficient algorithm to generate all the possible 3D vectors with integer coordinates and magnitude between $n-\delta$ and $n+\delta$, where $\delta$ is "small" compared to $n$.

This is equivalent to finding all the solutions of

$$(n-\delta)^2<\| v \|^2<(n+\delta)^2$$

with $\vec v \in \mathbf{Z}^3$.

Of course I only need to find half the solutions, because the other half will be given by

$$\vec v' = -\vec v$$

What is the best approach to solve this computational problem?