This paper focuses on the trajectory planning for a UAV on a low altitude terrain following/threat avoidance (TF/TA) mission. Using a grid-based approximated discretisation scheme, the continuous constrained optimisation problem into a search problem is transformed over a finite network. A variant of the Minimum Cost Network Flow (MCNF) to this problem is then applied. Based on using the Digital Terrain Elevation Data (DTED) and discrete dynamic equations of motion, the four-dimensional (4D) trajectory (three spatial and one time dimensions) from a starting point to an end point is obtained by minimising a cost function subject to dynamic and mission constraints of the UAV. For each arc in the grid, a cost function is considered as the combination of the arc length, fuel consumption and flight time. The proposed algorithm which considers dynamic and altitude constraints of the UAV explicitly is then used to obtain the feasible trajectory. The resultant trajectory can increase the survivability of the UAV using the threat region avoidance and the terrain masking effect. After obtaining the feasible trajectory, an improved algorithm is proposed to smooth the trajectory. The numeric results are presented to verify the capability of the proposed approach to generate admissible trajectory in minimum possible time in comparison to the previous works.