  We consider the set of Diophantine equations that arise in the context of the
barotropic vorticity equation on periodic domains, when nonlinear wave
interactions are studied to leading order in the amplitudes. The solutions to
this set of Diophantine equations are of interest in atmosphere (Rossby waves)
and Tokamak plasmas (drift waves), because they provide the values of the
spectral wavevectors that interact resonantly via three-wave interactions.
These come in "triads", i.e., groups of three wavevectors.
  We provide the full solution to the Diophantine equations in the case of
infinite Rossby deformation radius. The method is completely new, and relies on
mapping the unknown variables to rational points on quadratic forms of
"Minkowski" type. Classical methods invented centuries ago by Fermat, Euler,
Lagrange and Minkowski, are used to classify all solutions to our original
Diophantine equations, thus providing a computational method to generate
numerically all the resonant triads in the system. Our method has a clear
computational advantage over brute-force numerical search: on a 10000^2 grid,
the brute-force search would take 15 years using optimised C++ codes, whereas
our method takes about 40 minutes.
  The method is extended to generate quasi-resonant triads, which are defined
by relaxing the resonant condition on the frequencies, allowing for a small
mismatch. Quasi-resonances are robust with respect to physical perturbations,
unlike exact resonances. Therefore, the new method is really valuable in
practical terms. We show that the set of quasi-resonances form an intricate
network of clusters of connected triads, whose structure depends on the value
of the allowed mismatch. We provide some quantitative comparison between the
clusters' structure and the onset of fully nonlinear turbulence in the
barotropic vorticity equation, and provide perspectives for new research.
