Generating particle beams of controlled dimensions and divergence: I. Theory of particle motion in aerodynamic lenses and nozzle expansions