Igneous rocks form when magma cools and crystallizes either underground or at the surface. Sedimentary rocks form through the lithification of sediments. Metamorphic rocks form from pre-existing rocks undergoing changes due to heat, pressure, and chemically active fluids in the Earth's crust. The rock cycle illustrates how igneous, sedimentary, and metamorphic rocks are interrelated as they form and change over time through geological processes within the Earth.