Midpoint and distance formula