Multipoint optimal control with applications to space flight