Polarization phenomena of electrons and photons. I: General method and application to Compton scattering