The formation of multiple quadrotor UAVs with long navigation will encounter many flight constraints, so it is necessary to change the formation to avoid these constraints. In this paper, Voronoi graph theory is used to treat UAVs formation as a rigid body. The rigid body structure can be changed by changing the formation before different constraints, after passing constraints the rigid body structure remains the formation unchanged or form into the prescribed formation. The time-varying model is established to facilitate the use of optimization. Based on Gauss pseudospectral method (GPM), the path optimization of a single quadrotor UAV is carried out. The followed UAVs in formation are treated as constraints. The constraints of maximum turning radius and formation transformation time of other UAVs are considered in the optimization process. The minimum time required for formation transformation is optimized to solve the transformation optimization, and the performance index of trajectory optimization is to minimize the energy consumed by the leader quadrotor UAV within the specified time. Finally, the simulation proves the method proposed in this paper.