How midpoint formula is derived