The focus of this work is to present a novel methodology for optimal distribution of a swarm formation on either side of an obstacle, when evading the obstacle, to avoid overpopulation on the sides to reduce the agents' waiting delays, resulting in a reduced overall mission time and lower energy consumption. To handle this, the problem is divided into two main parts: 1) the disturbance phase: how to morph the formation optimally to avoid the obstacle in the least possible time in the situation at hand, and 2) the convergence phase: how to optimally resume the intended formation shape once the threat of potential collision has been eliminated. For the first problem, we develop a methodology which tests different formation morphing combinations and finds the optimal one, by utilizing trajectory, velocity, and coordinate information, to bypass the obstacle. For the second problem, we utilize thin-plate splines (TPS) inspired temperature function minimization method to bring the agents back from the distorted formation into the desired formation in an optimal manner, after collision avoidance has been successfully performed. Experimental results show that, in the considered test scenario, the proposed approach results in substantial energy savings as compared with the traditional methods.