A self-consistent model for the spiral arms of galaxies