This paper focuses on the three dimensional flight path planning for a UAV on a low altitude terrain following/terrain avoidance mission. Using an approximate grid-based discretisation scheme, we transform the continuous optimisation problem into a search problem over a finite network, and apply a variant of the shortest-path algorithm to this problem. In other words using the three dimensional terrain information, three dimensional flight path from a starting point to an end point, minimising a cost function and regarding the kinematics constraints of the UAV is calculated. A network flow model is constructed based on the digital terrain elevation data (DTED) and a layered network is obtained. The cost function for each arc is defined as the length of the arc, then a constrained shortest path algorithm which considers the kinematics and the altitude constraints of the UAV is used to obtain the best route. Moreover the important performance parameters of the UAV are discussed. Finally a new algorithm is proposed to smooth the path in order to reduce the workload of the autopilot and control system of the UAV. The numeric results are presented to verify the capability of the procedure to generate admissible route in minimum possible time in comparison to the previous procedures. So this algorithm is potentially suited for using in online systems.