  In ultracold-atom and ion experiments, flexible control of the direction and
amplitude of a uniform magnetic field is necessary. It is achieved almost
exclusively by controlling the current flowing through coils surrounding the
experimental chamber. Here, we present the design and characterization of a
modular, analog electronic circuit that enables three-dimensional control of a
magnetic field via the amplitude and direction of a current flowing through
three perpendicular pairs of coils. Each pair is controlled by one module, and
we are able to continuously change the current flowing thorough the coils in
the $\pm$4 A range using analog waveforms such that smooth crossing through
zero as the current's direction changes is possible. With the electrical
current stability at the 10$^{-5}$ level, the designed circuit enables
state-of-the-art ultracold experiments. As a benchmark, we use the circuit to
compensate stray magnetic fields that hinder efficient sub-Doppler cooling of
alkali atoms in gray molasses. We demonstrate how such compensation can be
achieved without actually measuring the stray fields present, thus speeding up
the process of optimization of various laser cooling stages.
