meteorite impact or a movement (earthquake) underwater.
The branch of astronomy that deals with the study of the universe including its origin and evolution is the branch, cosmology. This is a scientific approach to study the large scopes and scales properties of the whole universe.
There legs had to adapt to their new surroundings in order to survive so as time passed they evolved. I think it’s called natural selection.