Unmanned aerial vehicle(UAV) often flies in close proximity to terrain. The expansion in the number of low-altitude flight operations, along with increased operator workload, have made controlled flight into terrain the number one cause of loss of UAV. This paper is to give an overview of the Automatic Ground Collision Avoidance System (Auto-GCAS) program attempt to provide a system to eliminate that cause of UAV loss. The Auto-GCAS utilizes a digital terrain system with a terrain referenced navigation algorithm to locate the aircraft spatially with respect to the terrain. The terrain database around the aircraft is scanned, and a terrain profile is created. This paper presents a new compression algorithm called bubble terrain compression algorithm for Auto-GCAS of UAV. In this paper, optimal trajectory is considered as a minimax optimal control problem, which is solved using direct transcription of the continuous optimal control problem. Within a very general framework for solving such problems, we transform the non-smooth cost function into a constrained nonlinear programming problem. In the formulation, we solve for optimal collision avoidance manoeuvres. To ensure smooth derivatives of general two dimensional terrain, it is approximated using the optimal trajectories with disturbances in the initial conditions. Simulation results show that the UAV with the proposed methodology successfully achieves autonomous recovery maneuvers in MATLAB environment.