In this study, the three-dimensional optimal trajectory planning of an unmanned fixed-wing aerial vehicle was investigated for Terrain Following – Terrain Avoidance (TF-TA) purposes using the Direct Collocation method. For this purpose, firstly, the appropriate equations representing the translational movement of the aircraft were described. The three-dimensional optimal trajectory planning of the flying vehicle was formulated in the TF-TA manoeuvre as an optimal control problem. The terrain profile, as the main allowable height constraint was modelled using the Fractal Generation Method. The resulting optimal control problem was discretized by applying the Direct Collocation numerical technique and then, was transformed into a Nonlinear Programming Problem (NLP). The efficacy of the proposed method was demonstrated by extensive simulations, and it was particularly verified that the purposed approach can produce a solution satisfying almost all the performance and environmental constraints encountering in a low -altitude flight.