Petrology is the study of rocks, including their origin, composition, structure and distribution. There are three main types of rocks: igneous, sedimentary, and metamorphic. Igneous rocks form from the cooling of magma either below or above the Earth's surface. Sedimentary rocks form through the compaction and cementation of sediments. Metamorphic rocks form from the alteration of existing rocks through heat, pressure, and chemically active fluids in the Earth's crust.