how does the midpoint formula work