How is the Pythagorean theorem used to calculate the distance between two points?