how to find endpoints with midpoint