The collision between the Andromeda Galaxy (M31) and the Milky Way Galaxy (our galaxy) is indeed a result of their mutual gravitational attraction and their orbital paths around each other. However, there are a few key differences between the motion of galaxies and the motion of planets within a solar system that lead to a collision between galaxies.
Scale: Galaxies are significantly larger than individual planets, and their gravitational interactions span much greater distances. The distances between stars within a galaxy are also much larger than the distances between planets in a solar system. This means that the gravitational forces between galaxies can have a more significant impact on their motion compared to the relatively weaker gravitational forces between planets.
Interstellar Space: Unlike the largely empty space between planets in a solar system, galaxies contain a significant amount of interstellar gas and dust. As galaxies approach each other, the interstellar gas clouds can collide and interact, causing a drag effect that further slows down the galaxies' motion. This interaction increases the likelihood of a direct collision between the galactic structures.
Dynamical Friction: In the case of galaxy-galaxy interactions, a phenomenon called dynamical friction comes into play. As galaxies move through the intergalactic medium, the surrounding distribution of stars and dark matter creates a drag force that causes the galaxies to lose orbital energy. This leads to a gradual spiral-like descent of the galaxies toward each other, ultimately resulting in a merger or collision.
While planets in a solar system are relatively stable in their orbits due to their smaller masses and lack of significant external influences, galaxies can experience more complex and dynamic interactions. Over millions of years, the mutual gravitational attraction, combined with the effects of interstellar gas, dust, and dynamical friction, can cause the orbital paths of galaxies to decay, eventually leading to a merger or collision.
It is important to note that the collision between the Milky Way and Andromeda is expected to occur in about 4 billion years, and it is still an ongoing area of research. Our understanding of galactic dynamics and the specifics of such interactions continue to evolve as new observations and simulations become available.