By analyzing radioactive elements in meteorites, astronomers determined that the solar system formed 4.6 billion years ago from the gravitational collapse of a giant molecular cloud. This cloud collapsed over millions of years to form a rotating disk with the sun at the center. The planets formed from this disk, with the inner rocky planets closer to the sun and the outer gas giants farther away. In around 5 billion years, the Milky Way will collide with the Andromeda galaxy, and the solar system will be about 100,000 light years from the center of the new merged galaxy.