Motion of charged particles in a magnetic field